summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2023-03-31 13:55:28 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2023-03-31 13:55:28 +0000
commitdb69e680da3aa01572c19cdedb6448e74a01c790 (patch)
tree4b711a0d7253656f6be1cff3034058c290d90914 /test
parent90efd4480b07e2df04c3c1b3dd7917224757b64c (diff)
parentb4c1f29413f678c43d03afdaedd18bd18b23d59a (diff)
downloadsqlalchemy-db69e680da3aa01572c19cdedb6448e74a01c790.tar.gz
Merge "skip anno-only mixin columns that are overridden on subclasses" into main
Diffstat (limited to 'test')
-rw-r--r--test/orm/declarative/test_tm_future_annotations_sync.py68
-rw-r--r--test/orm/declarative/test_typed_mapping.py68
2 files changed, 136 insertions, 0 deletions
diff --git a/test/orm/declarative/test_tm_future_annotations_sync.py b/test/orm/declarative/test_tm_future_annotations_sync.py
index d63c01679..c1eecf970 100644
--- a/test/orm/declarative/test_tm_future_annotations_sync.py
+++ b/test/orm/declarative/test_tm_future_annotations_sync.py
@@ -2804,6 +2804,74 @@ class AllYourFavoriteHitsTest(fixtures.TestBase, testing.AssertsCompiledSQL):
"ON company.company_id = person.company_id",
)
+ @testing.variation("anno_type", ["plain", "typemap", "annotated"])
+ @testing.variation("inh_type", ["single", "joined"])
+ def test_mixin_interp_on_inh(self, decl_base, inh_type, anno_type):
+
+ global anno_col
+
+ if anno_type.typemap:
+ anno_col = Annotated[str, 30]
+
+ decl_base.registry.update_type_annotation_map({anno_col: String})
+
+ class Mixin:
+ foo: Mapped[anno_col]
+
+ elif anno_type.annotated:
+ anno_col = Annotated[str, mapped_column(String)]
+
+ class Mixin:
+ foo: Mapped[anno_col]
+
+ else:
+
+ class Mixin:
+ foo: Mapped[str]
+
+ class Employee(Mixin, decl_base):
+ __tablename__ = "employee"
+
+ id: Mapped[int] = mapped_column(primary_key=True)
+ name: Mapped[str]
+ type: Mapped[str]
+
+ __mapper_args__ = {
+ "polymorphic_on": "type",
+ "polymorphic_identity": "employee",
+ }
+
+ class Manager(Employee):
+ if inh_type.joined:
+ __tablename__ = "manager"
+
+ id: Mapped[int] = mapped_column( # noqa: A001
+ ForeignKey("employee.id"), primary_key=True
+ )
+
+ manager_data: Mapped[str] = mapped_column(nullable=True)
+
+ __mapper_args__ = {
+ "polymorphic_identity": "manager",
+ }
+
+ if inh_type.single:
+ self.assert_compile(
+ select(Manager),
+ "SELECT employee.id, employee.name, employee.type, "
+ "employee.foo, employee.manager_data FROM employee "
+ "WHERE employee.type IN (__[POSTCOMPILE_type_1])",
+ )
+ elif inh_type.joined:
+ self.assert_compile(
+ select(Manager),
+ "SELECT manager.id, employee.id AS id_1, employee.name, "
+ "employee.type, employee.foo, manager.manager_data "
+ "FROM employee JOIN manager ON employee.id = manager.id",
+ )
+ else:
+ inh_type.fail()
+
class WriteOnlyRelationshipTest(fixtures.TestBase):
def _assertions(self, A, B, lazy):
diff --git a/test/orm/declarative/test_typed_mapping.py b/test/orm/declarative/test_typed_mapping.py
index 3e34b11d3..514a4335f 100644
--- a/test/orm/declarative/test_typed_mapping.py
+++ b/test/orm/declarative/test_typed_mapping.py
@@ -2795,6 +2795,74 @@ class AllYourFavoriteHitsTest(fixtures.TestBase, testing.AssertsCompiledSQL):
"ON company.company_id = person.company_id",
)
+ @testing.variation("anno_type", ["plain", "typemap", "annotated"])
+ @testing.variation("inh_type", ["single", "joined"])
+ def test_mixin_interp_on_inh(self, decl_base, inh_type, anno_type):
+
+ # anno only: global anno_col
+
+ if anno_type.typemap:
+ anno_col = Annotated[str, 30]
+
+ decl_base.registry.update_type_annotation_map({anno_col: String})
+
+ class Mixin:
+ foo: Mapped[anno_col]
+
+ elif anno_type.annotated:
+ anno_col = Annotated[str, mapped_column(String)]
+
+ class Mixin:
+ foo: Mapped[anno_col]
+
+ else:
+
+ class Mixin:
+ foo: Mapped[str]
+
+ class Employee(Mixin, decl_base):
+ __tablename__ = "employee"
+
+ id: Mapped[int] = mapped_column(primary_key=True)
+ name: Mapped[str]
+ type: Mapped[str]
+
+ __mapper_args__ = {
+ "polymorphic_on": "type",
+ "polymorphic_identity": "employee",
+ }
+
+ class Manager(Employee):
+ if inh_type.joined:
+ __tablename__ = "manager"
+
+ id: Mapped[int] = mapped_column( # noqa: A001
+ ForeignKey("employee.id"), primary_key=True
+ )
+
+ manager_data: Mapped[str] = mapped_column(nullable=True)
+
+ __mapper_args__ = {
+ "polymorphic_identity": "manager",
+ }
+
+ if inh_type.single:
+ self.assert_compile(
+ select(Manager),
+ "SELECT employee.id, employee.name, employee.type, "
+ "employee.foo, employee.manager_data FROM employee "
+ "WHERE employee.type IN (__[POSTCOMPILE_type_1])",
+ )
+ elif inh_type.joined:
+ self.assert_compile(
+ select(Manager),
+ "SELECT manager.id, employee.id AS id_1, employee.name, "
+ "employee.type, employee.foo, manager.manager_data "
+ "FROM employee JOIN manager ON employee.id = manager.id",
+ )
+ else:
+ inh_type.fail()
+
class WriteOnlyRelationshipTest(fixtures.TestBase):
def _assertions(self, A, B, lazy):