]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add a test for #13021
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 3 Dec 2025 19:48:08 +0000 (14:48 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 4 Dec 2025 01:10:24 +0000 (20:10 -0500)
Confirmed the upstream fix for [1] given at [2] solves the issue
illustrated here, this patch adds a test for this case as our
existing tests did not catch this error in python 3.14.1.

Fixes: #13021
Change-Id: Ie6827279ccf2b2cb2e0fe6029aafdcfefc790f1f
(cherry picked from commit 133f14dabed44f7398039e2556bf9b7107f3922e)

test/orm/declarative/test_dc_transforms.py
test/orm/declarative/test_dc_transforms_future_anno_sync.py

index 06c92f038916b2253310d301c62281624490a89b..2e6d0aab247f4352135657ab7da1c60eeaf9b8a1 100644 (file)
@@ -1496,6 +1496,55 @@ class DataclassesForNonMappedClassesTest(fixtures.TestBase):
         n1 = Novel("the description")
         eq_(n1.description, "the description")
 
+    @testing.requires.python310
+    def test_cpython_142214(self, dc_decl_base):
+        """test for the cpython issue shown in issue #13021"""
+
+        class User(dc_decl_base):
+            __tablename__ = "user_account"
+
+            id: Mapped[int] = mapped_column(init=False, primary_key=True)
+            name: Mapped[str]
+
+        class CreatedByMixin(MappedAsDataclass, kw_only=True):
+            created_by_fk: Mapped[int] = mapped_column(
+                ForeignKey("user_account.id"), init=False
+            )
+
+            @declared_attr
+            @classmethod
+            def created_by(cls) -> Mapped[User]:
+                return relationship(foreign_keys=[cls.created_by_fk])
+
+        class Item(CreatedByMixin, dc_decl_base, kw_only=True):
+            __tablename__ = "item"
+
+            id: Mapped[int] = mapped_column(init=False, primary_key=True)
+            description: Mapped[str]
+
+        class SpecialItem(Item, kw_only=True):
+            __tablename__ = "special_item"
+
+            id: Mapped[int] = mapped_column(
+                ForeignKey("item.id"), init=False, primary_key=True
+            )
+            special_description: Mapped[str]
+
+        special_item = SpecialItem(
+            special_description="sd1",
+            description="d1",
+            created_by=User(name="u1"),
+        )
+
+        eq_(
+            special_item,
+            SpecialItem(
+                special_description="sd1",
+                description="d1",
+                created_by=User(name="u1"),
+            ),
+        )
+
 
 class DataclassArgsTest(fixtures.TestBase):
     dc_arg_names = ("init", "repr", "eq", "order", "unsafe_hash")
index 023b67a026eb4149a9a23f2d22fde74db92be31f..4e4fba2d03435cc38031b3fc057c3873a396dcde 100644 (file)
@@ -1515,6 +1515,55 @@ class DataclassesForNonMappedClassesTest(fixtures.TestBase):
         n1 = Novel("the description")
         eq_(n1.description, "the description")
 
+    @testing.requires.python310
+    def test_cpython_142214(self, dc_decl_base):
+        """test for the cpython issue shown in issue #13021"""
+
+        class User(dc_decl_base):
+            __tablename__ = "user_account"
+
+            id: Mapped[int] = mapped_column(init=False, primary_key=True)
+            name: Mapped[str]
+
+        class CreatedByMixin(MappedAsDataclass, kw_only=True):
+            created_by_fk: Mapped[int] = mapped_column(
+                ForeignKey("user_account.id"), init=False
+            )
+
+            @declared_attr
+            @classmethod
+            def created_by(cls) -> Mapped[User]:
+                return relationship(foreign_keys=[cls.created_by_fk])
+
+        class Item(CreatedByMixin, dc_decl_base, kw_only=True):
+            __tablename__ = "item"
+
+            id: Mapped[int] = mapped_column(init=False, primary_key=True)
+            description: Mapped[str]
+
+        class SpecialItem(Item, kw_only=True):
+            __tablename__ = "special_item"
+
+            id: Mapped[int] = mapped_column(
+                ForeignKey("item.id"), init=False, primary_key=True
+            )
+            special_description: Mapped[str]
+
+        special_item = SpecialItem(
+            special_description="sd1",
+            description="d1",
+            created_by=User(name="u1"),
+        )
+
+        eq_(
+            special_item,
+            SpecialItem(
+                special_description="sd1",
+                description="d1",
+                created_by=User(name="u1"),
+            ),
+        )
+
 
 class DataclassArgsTest(fixtures.TestBase):
     dc_arg_names = ("init", "repr", "eq", "order", "unsafe_hash")