Skip to content

Commit

Permalink
Fixed issue not allowing conflciting model names to be resolved corre…
Browse files Browse the repository at this point in the history
…ctly when building map of models to create schema from (pydantic#1912)
  • Loading branch information
jusexton committed Dec 2, 2020
1 parent de0657e commit 28ca33b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pydantic/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def get_flat_models_from_models(models: Sequence[Type['BaseModel']]) -> TypeMode


def get_long_model_name(model: TypeModelOrEnum) -> str:
return f'{model.__module__}__{model.__name__}'.replace('.', '__')
return str(model)


def field_type_schema(
Expand Down
22 changes: 19 additions & 3 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,9 +1111,9 @@ class Baz(BaseModel):
Foo: 'Foo',
Bar: 'Bar',
Baz: 'Baz',
ModelA: 'pydantic_schema_test__modulea__modela__Model',
ModelB: 'pydantic_schema_test__moduleb__modelb__Model',
ModelC: 'pydantic_schema_test__modulec__modelc__Model',
ModelA: '<class \'pydantic_schema_test.modulea.modela.Model\'>',
ModelB: '<class \'pydantic_schema_test.moduleb.modelb.Model\'>',
ModelC: '<class \'pydantic_schema_test.modulec.modelc.Model\'>',
}


Expand Down Expand Up @@ -2097,3 +2097,19 @@ class Model(BaseModel):
'properties': {'a': {'title': 'A', 'type': 'string'}},
'required': ['a'],
}


def test_multiple_nested_model_declarations_do_not_raise_error():
class ModelOne(BaseModel):
class NestedModel(BaseModel):
a: float

nested: NestedModel

class ModelTwo(BaseModel):
class NestedModel(BaseModel):
b: float

nested: NestedModel

schema([ModelOne, ModelTwo])

0 comments on commit 28ca33b

Please sign in to comment.