From 9809b5bc8323712fe41d1e7a92352da8a07ed69a Mon Sep 17 00:00:00 2001 From: Daniil Fajnberg <60156134+daniil-berg@users.noreply.github.com> Date: Mon, 23 Oct 2023 13:59:06 +0000 Subject: [PATCH] =?utf8?q?=F0=9F=90=9B=20Fix=20allowing=20using=20a=20`For?= =?utf8?q?eignKey`=20directly,=20remove=20repeated=20column=20construction?= =?utf8?q?=20from=20`SQLModelMetaclass.=5F=5Finit=5F=5F`=20and=20upgrade?= =?utf8?q?=20minimum=20SQLAlchemy=20to=20`>=3D1.4.36`=20(#443)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Co-authored-by: Sebastián Ramírez --- pyproject.toml | 2 +- sqlmodel/main.py | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 94fe55d2..57426b5d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ classifiers = [ [tool.poetry.dependencies] python = "^3.7" -SQLAlchemy = ">=1.4.29,<2.0.0" +SQLAlchemy = ">=1.4.36,<2.0.0" pydantic = "^1.8.2" sqlalchemy2-stubs = {version = "*", allow-prereleases = true} diff --git a/sqlmodel/main.py b/sqlmodel/main.py index a32be42c..07e600e4 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -334,14 +334,10 @@ class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta): base_is_table = True break if getattr(cls.__config__, "table", False) and not base_is_table: - dict_used = dict_.copy() - for field_name, field_value in cls.__fields__.items(): - dict_used[field_name] = get_column_from_field(field_value) for rel_name, rel_info in cls.__sqlmodel_relationships__.items(): if rel_info.sa_relationship: # There's a SQLAlchemy relationship declared, that takes precedence # over anything else, use that and continue with the next attribute - dict_used[rel_name] = rel_info.sa_relationship setattr(cls, rel_name, rel_info.sa_relationship) # Fix #315 continue ann = cls.__annotations__[rel_name] @@ -375,9 +371,11 @@ class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta): rel_value: RelationshipProperty = relationship( # type: ignore relationship_to, *rel_args, **rel_kwargs ) - dict_used[rel_name] = rel_value setattr(cls, rel_name, rel_value) # Fix #315 - DeclarativeMeta.__init__(cls, classname, bases, dict_used, **kw) + # SQLAlchemy no longer uses dict_ + # Ref: https://github.com/sqlalchemy/sqlalchemy/commit/428ea01f00a9cc7f85e435018565eb6da7af1b77 + # Tag: 1.4.36 + DeclarativeMeta.__init__(cls, classname, bases, dict_, **kw) else: ModelMetaclass.__init__(cls, classname, bases, dict_, **kw) -- 2.47.2