apply fix for new pydantic

This commit is contained in:
collerek
2021-02-28 09:20:42 +01:00
parent fd38ae2a40
commit 0c781c4d52
2 changed files with 16 additions and 11 deletions

View File

@ -93,9 +93,11 @@ class BaseField(FieldInfo):
:rtype: bool :rtype: bool
""" """
return ( return (
field_name not in ["default", "default_factory", "alias"] field_name not in ["default", "default_factory", "alias",
and not field_name.startswith("__") "allow_mutation"]
and hasattr(cls, field_name) and not field_name.startswith("__")
and hasattr(cls, field_name)
and not callable(getattr(cls, field_name))
) )
@classmethod @classmethod
@ -204,7 +206,7 @@ class BaseField(FieldInfo):
:rtype: bool :rtype: bool
""" """
return cls.default is not None or ( return cls.default is not None or (
cls.server_default is not None and use_server cls.server_default is not None and use_server
) )
@classmethod @classmethod
@ -237,7 +239,7 @@ class BaseField(FieldInfo):
ondelete=con.ondelete, ondelete=con.ondelete,
onupdate=con.onupdate, onupdate=con.onupdate,
name=f"fk_{cls.owner.Meta.tablename}_{cls.to.Meta.tablename}" name=f"fk_{cls.owner.Meta.tablename}_{cls.to.Meta.tablename}"
f"_{cls.to.get_column_alias(cls.to.Meta.pkname)}_{cls.name}", f"_{cls.to.get_column_alias(cls.to.Meta.pkname)}_{cls.name}",
) )
for con in cls.constraints for con in cls.constraints
] ]
@ -270,10 +272,10 @@ class BaseField(FieldInfo):
@classmethod @classmethod
def expand_relationship( def expand_relationship(
cls, cls,
value: Any, value: Any,
child: Union["Model", "NewBaseModel"], child: Union["Model", "NewBaseModel"],
to_register: bool = True, to_register: bool = True,
) -> Any: ) -> Any:
""" """
Function overwritten for relations, in basic field the value is returned as is. Function overwritten for relations, in basic field the value is returned as is.
@ -301,7 +303,7 @@ class BaseField(FieldInfo):
:rtype: None :rtype: None
""" """
if cls.owner is not None and ( if cls.owner is not None and (
cls.owner == cls.to or cls.owner.Meta == cls.to.Meta cls.owner == cls.to or cls.owner.Meta == cls.to.Meta
): ):
cls.self_reference = True cls.self_reference = True
cls.self_reference_primary = cls.name cls.self_reference_primary = cls.name

View File

@ -52,8 +52,11 @@ setup(
package_data={PACKAGE: ["py.typed"]}, package_data={PACKAGE: ["py.typed"]},
include_package_data=True, include_package_data=True,
zip_safe=False, zip_safe=False,
python_requires=">=3.6",
data_files=[("", ["LICENSE.md"])], data_files=[("", ["LICENSE.md"])],
install_requires=["databases", "pydantic>=1.5", "sqlalchemy", "typing_extensions"], install_requires=["databases>=0.3.2,<=0.4.1", "pydantic>=1.6.1,<=1.8",
"sqlalchemy>=1.3.18,<=1.3.23",
"typing_extensions>=3.7,<=3.7.4.3"],
extras_require={ extras_require={
"postgresql": ["asyncpg", "psycopg2"], "postgresql": ["asyncpg", "psycopg2"],
"mysql": ["aiomysql", "pymysql"], "mysql": ["aiomysql", "pymysql"],