]> 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>
Wed, 3 Dec 2025 19:48:08 +0000 (14:48 -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

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

index 46780e3806a312d0ea6f4e62868b32b788336d41..eab63ff55cc9708d818e5e245ae297bd64d10f80 100644 (file)
@@ -1690,6 +1690,54 @@ class DataclassesForNonMappedClassesTest(fixtures.TestBase):
         n1 = Novel("the description")
         eq_(n1.description, "the description")
 
+    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 = (
index 7724259396b8e7b7f853485e3ef1728d15242901..6328edb60571f29a326a73d3fc2ca9801fa2f436 100644 (file)
@@ -1707,6 +1707,54 @@ class DataclassesForNonMappedClassesTest(fixtures.TestBase):
         n1 = Novel("the description")
         eq_(n1.description, "the description")
 
+    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 = (