Skip to content

Commit 2d812a8

Browse files
committed
Reverting problematic fix from 2.6 release, fixing schema building bug (#8718)
1 parent 8e790d5 commit 2d812a8

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

pydantic/_internal/_generate_schema.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,6 @@ def clean_schema(self, schema: CoreSchema) -> CoreSchema:
437437
if collect_invalid_schemas(schema):
438438
raise self.CollectedInvalid()
439439
schema = validate_core_schema(schema)
440-
if 'definitions' in schema:
441-
schema['definitions'] = list(reversed(schema['definitions']))
442440
return schema
443441

444442
def collect_definitions(self, schema: CoreSchema) -> CoreSchema:

tests/test_discriminated_union.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,7 @@ class DiscriminatedModel(BaseModel):
17001700
assert exc_info.code == 'callable-discriminator-no-tag'
17011701

17021702

1703+
@pytest.mark.xfail(reason='Issue not yet fixed, see: https://github.com/pydantic/pydantic/issues/8271.')
17031704
def test_presence_of_discriminator_when_generating_type_adaptor_json_schema_definitions() -> None:
17041705
class ItemType(str, Enum):
17051706
ITEM1 = 'item1'

tests/test_json_schema.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5879,3 +5879,31 @@ class Model(BaseModel):
58795879
x: BaseModel
58805880

58815881
assert 'description' not in Model.model_json_schema()['$defs']['BaseModel']
5882+
5883+
5884+
def test_recursive_json_schema_build() -> None:
5885+
"""
5886+
Schema build for this case is a bit complicated due to the recursive nature of the models.
5887+
This was reported as broken in https://github.com/pydantic/pydantic/issues/8689, which was
5888+
originally caused by the change made in https://github.com/pydantic/pydantic/pull/8583, which has
5889+
since been reverted.
5890+
"""
5891+
5892+
class AllowedValues(str, Enum):
5893+
VAL1 = 'Val1'
5894+
VAL2 = 'Val2'
5895+
5896+
class ModelA(BaseModel):
5897+
modelA_1: AllowedValues = Field(..., max_length=60)
5898+
5899+
class ModelB(ModelA):
5900+
modelB_1: typing.List[ModelA]
5901+
5902+
class ModelC(BaseModel):
5903+
modelC_1: ModelB
5904+
5905+
class Model(BaseModel):
5906+
b: ModelB
5907+
c: ModelC
5908+
5909+
assert Model.model_json_schema()

0 commit comments

Comments
 (0)