Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in test_json_schema with Pydantic 2.9 #213

Closed
musicinmybrain opened this issue Sep 11, 2024 · 1 comment · Fixed by #215
Closed

Regression in test_json_schema with Pydantic 2.9 #213

musicinmybrain opened this issue Sep 11, 2024 · 1 comment · Fixed by #215

Comments

@musicinmybrain
Copy link
Contributor

$ gh repo clone pydantic/pydantic-extra-types
$ cd pydantic-extra-types
$ python3.12 -m venv _e
$ . _e/bin/activate
(_e) $ pip install -e .[all]
(_e) $ pip install -r requirements/testing.in
(_e) $ python -m pytest
[…]
=================================================================================================== FAILURES ===================================================================================================
_______________________________________________________________________________________________ test_json_schema _______________________________________________________________________________________________

    def test_json_schema():
        class Model(BaseModel):
            value: Coordinate

        assert Model.model_json_schema(mode='validation')['$defs']['Coordinate'] == {
            'properties': {
                'latitude': {'maximum': 90.0, 'minimum': -90.0, 'title': 'Latitude', 'type': 'number'},
                'longitude': {'maximum': 180.0, 'minimum': -180.0, 'title': 'Longitude', 'type': 'number'},
            },  
            'required': ['latitude', 'longitude'],
            'title': 'Coordinate',
            'type': 'object',
        }   
        assert Model.model_json_schema(mode='validation')['properties']['value'] == {
            'anyOf': [
                {'$ref': '#/$defs/Coordinate'},
                {
                    'maxItems': 2,
                    'minItems': 2,
                    'prefixItems': [{'type': 'number'}, {'type': 'number'}],
                    'type': 'array',
                },
                {'type': 'string'},
            ],
            'title': 'Value',
        }
>       assert Model.model_json_schema(mode='serialization') == {   
            '$defs': {
                'Coordinate': {
                    'properties': {
                        'latitude': {'maximum': 90.0, 'minimum': -90.0, 'title': 'Latitude', 'type': 'number'},
                        'longitude': {'maximum': 180.0, 'minimum': -180.0, 'title': 'Longitude', 'type': 'number'},
                    },
                    'required': ['latitude', 'longitude'],
                    'title': 'Coordinate',
                    'type': 'object',
                }
            },
            'properties': {'value': {'allOf': [{'$ref': '#/$defs/Coordinate'}], 'title': 'Value'}},
            'required': ['value'],
            'title': 'Model',
            'type': 'object',
        }
E       AssertionError: assert {'$defs': {'C... 'Model', ...} == {'$defs': {'C... 'Model', ...}
E         
E         Omitting 4 identical items, use -vv to show
E         Differing items:
E         {'properties': {'value': {'$ref': '#/$defs/Coordinate', 'title': 'Value'}}} != {'properties': {'value': {
E         
E         ...Full output truncated (2 lines hidden), use '-vv' to show

tests/test_coordinate.py:180: AssertionError
                                          Summary of Failures                                          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓
┃  File                      ┃  Function          ┃  Function Line  ┃  Error Line  ┃  Error           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩
│  tests/test_coordinate.py  │  test_json_schema  │  154            │  180         │  AssertionError  │
└────────────────────────────┴────────────────────┴─────────────────┴──────────────┴──────────────────┘
Results (5.50s):
         1 failed
     13056 passed
(_e) $ pip install pydantic==2.8.2
(_e) $ python -m pytest
[…]
Results (5.60s):
     13057 passed
@musicinmybrain
Copy link
Contributor Author

Looking at

E         Differing items:
E         {'properties': {'value': {'$ref': '#/$defs/Coordinate', 'title': 'Value'}}} != {'properties': {'value': {'allOf': [{'$ref': '#/$defs/Coordinate'}], 'title': 'Value'}}}

it seems the schemas are not identical, but are equivalent.

musicinmybrain added a commit to musicinmybrain/pydantic-extra-types that referenced this issue Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant