8000 'exclusiveMaximum': inf probably shouldn't appear in model schema · Issue #1417 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content

'exclusiveMaximum': inf probably shouldn't appear in model schema #1417

@jessekv

Description

@jessekv

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

pydantic version: 1.5
pydantic compiled: True
python version: 3.7.5 (default, Nov  7 2019, 10:50:52)  [GCC 8.3.0]
platform: Linux-4.4.0-18362-Microsoft-x86_64-with-Ubuntu-18.04-bionic
optional deps. installed: ['typing-extensions']

Example code:

import math
from pydantic import BaseModel, Field

class MyModel(BaseModel):
    myfloat: float = Field(..., lt=math.inf)
print(MyModel.schema())
# {'title': 'MyModel', 'type': 'object', 'properties': {'myfloat': {'title': 'Myfloat', 'exclusiveMaximum': inf, 'type': 'number'}}, 'required': ['myfloat']}

The inf is not json-compliant:

{
  "properties": {
    "myfloat": {
      "exclusiveMaximum": inf,
      "title": "Myfloat"
5D5A
,
      "type": "number"
    }
  },
  "required": [
    "myfloat"
  ],
  "title": "MyModel",
  "type": "object"
}

However, json-compliant strings cannot include inf anyway, so the presence of 'exclusiveMaximum': inf (or conversely, 'exclusiveMinimum': -inf) in the schema seems to be a bug.

Note that the reason that I have lt=math.inf in the first place is because I am trying to limit myfloat to real-valued floats. Perhaps pydantic provides a better way to do this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0