Skip to content

Commit

Permalink
Reverting problematic fix from 2.6 release, fixing schema building bug (
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-runkle committed Feb 2, 2024
1 parent 9ac7c6c commit 8364920
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
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()

0 comments on commit 8364920

Please sign in to comment.