summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoresoh <sean.so.oh@gmail.com>2020-12-18 21:59:31 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-12-19 12:42:33 -0500
commitb1a24ef41ecda38add2a62e33122f2111502dbea (patch)
treeeaedb18ee9a57c2f1bf59bc1f6acbbb32ce06f10
parent8294a336b1e6f23b5a7244e7aa457321fd3580bd (diff)
downloadsqlalchemy-b1a24ef41ecda38add2a62e33122f2111502dbea.tar.gz
Repair and cover adaption call w/ ORM having()
Fixed 1.4 regression where the use of :meth:`_orm.Query.having` in conjunction with queries with internally adapted SQL elements (common in inheritance scenarios) would fail due to an incorrect function call. Pull request courtesy esoh. Fixes: #5781 Closes: #5782 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5782 Pull-request-sha: 5d37b0be0db68ec2a4dfea552ee47bcb3ef6778c Change-Id: I123b2c0a4a23b7c7c72929dec79801726afc71ee
-rw-r--r--doc/build/changelog/unreleased_14/5781.rst9
-rw-r--r--lib/sqlalchemy/orm/context.py2
-rw-r--r--test/orm/inheritance/test_polymorphic_rel.py10
-rw-r--r--test/orm/inheritance/test_single.py18
4 files changed, 37 insertions, 2 deletions
diff --git a/doc/build/changelog/unreleased_14/5781.rst b/doc/build/changelog/unreleased_14/5781.rst
new file mode 100644
index 000000000..ba1ccec7b
--- /dev/null
+++ b/doc/build/changelog/unreleased_14/5781.rst
@@ -0,0 +1,9 @@
+.. change::
+ :tags: bug, orm
+ :tickets: 5781
+
+ Fixed 1.4 regression where the use of :meth:`_orm.Query.having` in
+ conjunction with queries with internally adapted SQL elements (common in
+ inheritance scenarios) would fail due to an incorrect function call. Pull
+ request courtesy esoh.
+
diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py
index cd654ed3d..41b2146a3 100644
--- a/lib/sqlalchemy/orm/context.py
+++ b/lib/sqlalchemy/orm/context.py
@@ -585,7 +585,7 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
if query._having_criteria:
self._having_criteria = tuple(
- current_adapter(crit, True, True) if current_adapter else crit
+ current_adapter(crit, True) if current_adapter else crit
for crit in query._having_criteria
)
diff --git a/test/orm/inheritance/test_polymorphic_rel.py b/test/orm/inheritance/test_polymorphic_rel.py
index 51277943f..84ef22d52 100644
--- a/test/orm/inheritance/test_polymorphic_rel.py
+++ b/test/orm/inheritance/test_polymorphic_rel.py
@@ -2360,4 +2360,12 @@ class PolymorphicAliasedJoinsTest(
class PolymorphicJoinsTest(_PolymorphicTestBase, _PolymorphicJoins):
- pass
+ def test_having_group_by(self):
+ sess = create_session()
+ eq_(
+ sess.query(Person.name)
+ .group_by(Person.name)
+ .having(Person.name == "dilbert")
+ .all(),
+ [("dilbert",)],
+ )
diff --git a/test/orm/inheritance/test_single.py b/test/orm/inheritance/test_single.py
index aa17f4300..cbe6bd238 100644
--- a/test/orm/inheritance/test_single.py
+++ b/test/orm/inheritance/test_single.py
@@ -416,6 +416,24 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
},
)
+ def test_having(self):
+
+ Engineer, Manager = self.classes("Engineer", "Manager")
+
+ sess = create_session()
+
+ self.assert_compile(
+ sess.query(Engineer)
+ .group_by(Engineer.employee_id)
+ .having(Engineer.name == "js"),
+ "SELECT employees.employee_id AS employees_employee_id, "
+ "employees.name AS employees_name, employees.manager_data "
+ "AS employees_manager_data, employees.engineer_info "
+ "AS employees_engineer_info, employees.type AS employees_type "
+ "FROM employees WHERE employees.type IN ([POSTCOMPILE_type_1]) "
+ "GROUP BY employees.employee_id HAVING employees.name = :name_1",
+ )
+
def test_from_self_count(self):
Engineer = self.classes.Engineer