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

Reverting problematic fix from 2.6 release, fixing schema building bug #8718

Merged
merged 1 commit into from Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions pydantic/_internal/_generate_schema.py
Expand Up @@ -438,8 +438,6 @@ def clean_schema(self, schema: CoreSchema) -> CoreSchema:
if collect_invalid_schemas(schema):
raise self.CollectedInvalid()
schema = validate_core_schema(schema)
if 'definitions' in schema:
schema['definitions'] = list(reversed(schema['definitions']))
return schema

def collect_definitions(self, schema: CoreSchema) -> CoreSchema:
Expand Down
1 change: 1 addition & 0 deletions tests/test_discriminated_union.py
Expand Up @@ -1700,6 +1700,7 @@ class DiscriminatedModel(BaseModel):
assert exc_info.code == 'callable-discriminator-no-tag'


@pytest.mark.xfail(reason='Issue not yet fixed, see: https://github.com/pydantic/pydantic/issues/8271.')
def test_presence_of_discriminator_when_generating_type_adaptor_json_schema_definitions() -> None:
class ItemType(str, Enum):
ITEM1 = 'item1'
Expand Down
28 changes: 28 additions & 0 deletions tests/test_json_schema.py
Expand Up @@ -5879,3 +5879,31 @@ class Model(BaseModel):
x: BaseModel

assert 'description' not in Model.model_json_schema()['$defs']['BaseModel']


def test_recursive_json_schema_build() -> None:
"""
Schema build for this case is a bit complicated due to the recursive nature of the models.
This was reported as broken in https://github.com/pydantic/pydantic/issues/8689, which was
originally caused by the change made in https://github.com/pydantic/pydantic/pull/8583, which has
since been reverted.
"""

class AllowedValues(str, Enum):
VAL1 = 'Val1'
VAL2 = 'Val2'

class ModelA(BaseModel):
modelA_1: AllowedValues = Field(..., max_length=60)

class ModelB(ModelA):
modelB_1: typing.List[ModelA]

class ModelC(BaseModel):
modelC_1: ModelB

class Model(BaseModel):
b: ModelB
c: ModelC

assert Model.model_json_schema()