From a0a52e79eec780206bc014f301d301f345ec57a0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 24 May 2024 10:58:02 -0400 Subject: [PATCH] Add test for issue 11412 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) --- doc/build/changelog/changelog_14.rst | 7 +++- doc/build/changelog/changelog_20.rst | 7 +++- test/orm/inheritance/test_single.py | 52 ++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/doc/build/changelog/changelog_14.rst b/doc/build/changelog/changelog_14.rst index 1d6a3f775a..47586bfd4f 100644 --- a/doc/build/changelog/changelog_14.rst +++ b/doc/build/changelog/changelog_14.rst @@ -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 diff --git a/doc/build/changelog/changelog_20.rst b/doc/build/changelog/changelog_20.rst index 4b3c9b9000..b0194baa5b 100644 --- a/doc/build/changelog/changelog_20.rst +++ b/doc/build/changelog/changelog_20.rst @@ -972,12 +972,17 @@ .. 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 diff --git a/test/orm/inheritance/test_single.py b/test/orm/inheritance/test_single.py index f45194f29c..bfdf0b7bcf 100644 --- a/test/orm/inheritance/test_single.py +++ b/test/orm/inheritance/test_single.py @@ -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) -- 2.47.2