]> 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>
Sun, 26 May 2024 20:34:30 +0000 (16:34 -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
(cherry picked from commit 61d227a7d4f7be7b1f6fa72171d01c60e571939e)
(cherry picked from commit a0a52e79eec780206bc014f301d301f345ec57a0)

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

index 7ed34ad2ddf5b2c53c57b4df836fae282ac55c53..01572e55c83c2564720f63ef6dfafe8a038a7e6e 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 c11b40cbbf2fd69e891d945a7d531d0c71789b91..2347114286020da3b23f0d81391c18bf5e859c67 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -108,7 +108,7 @@ enable-extensions = G
 
 # E203 is due to https://github.com/PyCQA/pycodestyle/issues/373
 ignore =
-    A003, A004
+    A003, A004, A005, A006
     D,
     E203,E305,E711,E712,E721,E722,E741,
     N801,N802,N806,
index 041e635ab10296485d3e5c99f4f835089b2e3ca0..afb0ce95dca78bfa5c88fa549f1593713ab3d319 100644 (file)
@@ -396,6 +396,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)