]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add test for issue 11412
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 24 May 2024 14:58:02 +0000 (10:58 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 24 May 2024 14:58:02 +0000 (10:58 -0400)
Issue #10365 was found to also fix an issue where
single-inheritance criteria would not be correctly applied to a
subclass entity that only appeared in the ``select_from()`` list.

Fixes: #11412
Change-Id: Ic865737a3d075fceee346eea8044345233038f72

doc/build/changelog/changelog_14.rst
doc/build/changelog/changelog_20.rst
test/orm/inheritance/test_single.py

index 1d6a3f775aef0bca55dbd5aec5e2f488cf15a656..47586bfd4f682301a6cd53fe9c2073bd72dc6f0f 100644 (file)
@@ -23,7 +23,7 @@ This document details individual issue-level changes made throughout
 
     .. change::
         :tags: bug, orm
-        :tickets: 10365
+        :tickets: 10365, 11412
 
         Fixed bug where ORM :func:`_orm.with_loader_criteria` would not apply
         itself to a :meth:`_sql.Select.join` where the ON clause were given as a
@@ -31,6 +31,11 @@ This document details individual issue-level changes made throughout
 
         This is a backport of the same issue fixed in version 2.0 for 2.0.22.
 
+        **update** - this was found to also fix an issue where
+        single-inheritance criteria would not be correctly applied to a
+        subclass entity that only appeared in the ``select_from()`` list,
+        see :ticket:`11412`
+
 .. changelog::
     :version: 1.4.51
     :released: January 2, 2024
index 4b3c9b900051f22c2b6a29ad41f3fdd78ae7a1c1..b0194baa5b87cb333581420b52ee475297fb13cf 100644 (file)
 
     .. change::
         :tags: bug, orm
-        :tickets: 10365
+        :tickets: 10365, 11412
 
         Fixed bug where ORM :func:`_orm.with_loader_criteria` would not apply
         itself to a :meth:`_sql.Select.join` where the ON clause were given as a
         plain SQL comparison, rather than as a relationship target or similar.
 
+        **update** - this was found to also fix an issue where
+        single-inheritance criteria would not be correctly applied to a
+        subclass entity that only appeared in the ``select_from()`` list,
+        see :ticket:`11412`
+
     .. change::
         :tags: bug, sql
         :tickets: 10408
index f45194f29c52aeb4783b74ee5b6d5c3fcce55cbf..bfdf0b7bcfa3a56dedba4a25a4c8ea9f7c549df0 100644 (file)
@@ -377,6 +377,58 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
             "WHERE employees_1.type IN (__[POSTCOMPILE_type_1])",
         )
 
+    @testing.combinations(
+        (
+            lambda Engineer, Report: select(Report.report_id)
+            .select_from(Engineer)
+            .join(Engineer.reports),
+        ),
+        (
+            lambda Engineer, Report: select(Report.report_id).select_from(
+                orm_join(Engineer, Report, Engineer.reports)
+            ),
+        ),
+        (
+            lambda Engineer, Report: select(Report.report_id).join_from(
+                Engineer, Report, Engineer.reports
+            ),
+        ),
+        (
+            lambda Engineer, Report: select(Report.report_id)
+            .select_from(Engineer)
+            .join(Report),
+        ),
+        argnames="stmt_fn",
+    )
+    @testing.combinations(True, False, argnames="alias_engineer")
+    def test_select_col_only_from_w_join(self, stmt_fn, alias_engineer):
+        """test #11412 which seems to have been fixed by #10365"""
+
+        Engineer = self.classes.Engineer
+        Report = self.classes.Report
+
+        if alias_engineer:
+            Engineer = aliased(Engineer)
+        stmt = testing.resolve_lambda(
+            stmt_fn, Engineer=Engineer, Report=Report
+        )
+
+        if alias_engineer:
+            self.assert_compile(
+                stmt,
+                "SELECT reports.report_id FROM employees AS employees_1 "
+                "JOIN reports ON employees_1.employee_id = "
+                "reports.employee_id WHERE employees_1.type "
+                "IN (__[POSTCOMPILE_type_1])",
+            )
+        else:
+            self.assert_compile(
+                stmt,
+                "SELECT reports.report_id FROM employees JOIN reports "
+                "ON employees.employee_id = reports.employee_id "
+                "WHERE employees.type IN (__[POSTCOMPILE_type_1])",
+            )
+
     @testing.combinations(
         (
             lambda Engineer, Report: select(Report)