From 6a42b827766b00bfe56c6b163905fff0c1e8f140 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) (cherry picked from commit a0a52e79eec780206bc014f301d301f345ec57a0) --- doc/build/changelog/changelog_14.rst | 7 +++- setup.cfg | 2 +- test/orm/inheritance/test_single.py | 52 ++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/doc/build/changelog/changelog_14.rst b/doc/build/changelog/changelog_14.rst index 7ed34ad2dd..01572e55c8 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/setup.cfg b/setup.cfg index c11b40cbbf..2347114286 100644 --- 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, diff --git a/test/orm/inheritance/test_single.py b/test/orm/inheritance/test_single.py index 041e635ab1..afb0ce95dc 100644 --- a/test/orm/inheritance/test_single.py +++ b/test/orm/inheritance/test_single.py @@ -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) -- 2.47.2