]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
🐛 Fix allowing using a `ForeignKey` directly, remove repeated column construction...
authorDaniil Fajnberg <60156134+daniil-berg@users.noreply.github.com>
Mon, 23 Oct 2023 13:59:06 +0000 (13:59 +0000)
committerGitHub <noreply@github.com>
Mon, 23 Oct 2023 13:59:06 +0000 (17:59 +0400)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
pyproject.toml
sqlmodel/main.py

index 94fe55d2e096e2d573057770af8ff57c0a78a3d5..57426b5d2ab18eb63a7a3b1b984ef7b6e29efd1f 100644 (file)
@@ -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}
 
index a32be42c65bf278ac61025978b5929acd2f1136d..07e600e4d45b1ce262d2acaea23a565fc6b9f8d8 100644 (file)
@@ -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)