From: Mike Bayer Date: Wed, 3 Dec 2025 19:48:08 +0000 (-0500) Subject: Add a test for #13021 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=133f14dabed44f7398039e2556bf9b7107f3922e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add a test for #13021 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 --- diff --git a/test/orm/declarative/test_dc_transforms.py b/test/orm/declarative/test_dc_transforms.py index 46780e3806..eab63ff55c 100644 --- a/test/orm/declarative/test_dc_transforms.py +++ b/test/orm/declarative/test_dc_transforms.py @@ -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 = ( diff --git a/test/orm/declarative/test_dc_transforms_future_anno_sync.py b/test/orm/declarative/test_dc_transforms_future_anno_sync.py index 7724259396..6328edb605 100644 --- a/test/orm/declarative/test_dc_transforms_future_anno_sync.py +++ b/test/orm/declarative/test_dc_transforms_future_anno_sync.py @@ -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 = (