Minor changes

This commit is contained in:
Daniil Fajnberg 2022-08-03 11:29:54 +02:00
parent a64708dedd
commit 20272c4b4a
2 changed files with 5 additions and 5 deletions

View File

@ -54,7 +54,7 @@ def from_sqla(db_model: Type[DeclarativeMeta], incl_many_to_one: bool = True, in
config: Type[BaseConfig] = OrmConfig, exclude: Container[str] = (), config: Type[BaseConfig] = OrmConfig, exclude: Container[str] = (),
add_fields: dict[str, FieldDef] = None): add_fields: dict[str, FieldDef] = None):
assert isinstance(db_model, DeclarativeMeta) assert isinstance(db_model, DeclarativeMeta)
assert not (incl_one_to_many and incl_many_to_one) assert not (incl_one_to_many and incl_many_to_one), "Pydantic is unable to handle the circular relationship"
fields = {} fields = {}
for attr in inspect(db_model).attrs: for attr in inspect(db_model).attrs:
if attr.key in exclude: if attr.key in exclude:

View File

@ -9,7 +9,6 @@ from orm2pydantic.sqla import from_sqla
ORMBase = declarative_base() ORMBase = declarative_base()
engine = create_engine("sqlite://")
def default_factory() -> str: return '1' def default_factory() -> str: return '1'
@ -65,11 +64,12 @@ class Address(AbstractBase):
def main_test() -> None: def main_test() -> None:
engine = create_engine("sqlite://")
AbstractBase.metadata.create_all(engine) AbstractBase.metadata.create_all(engine)
from_sqla(StateProvince) _PydanticStateProvince = from_sqla(StateProvince)
from_sqla(City) _PydanticCity = from_sqla(City)
from_sqla(Street) _PydanticStreet = from_sqla(Street)
_PydanticAddress = from_sqla(Address) _PydanticAddress = from_sqla(Address)
with Session(engine) as session: with Session(engine) as session: