From 5d37b0be0db68ec2a4dfea552ee47bcb3ef6778c Mon Sep 17 00:00:00 2001 From: esoh Date: Thu, 17 Dec 2020 21:44:44 -0800 Subject: [PATCH] Fixes: #5781 - fix bug with having criteria with adapters --- lib/sqlalchemy/orm/context.py | 2 +- test/orm/declarative/test_inheritance.py | 30 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py index cd654ed3d6..41b2146a3d 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/declarative/test_inheritance.py b/test/orm/declarative/test_inheritance.py index d8847ed402..6ae54bd712 100644 --- a/test/orm/declarative/test_inheritance.py +++ b/test/orm/declarative/test_inheritance.py @@ -654,6 +654,36 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): Engineer(name="vlad", primary_language="cobol"), ) + def test_single_having(self): + """test single table inheritance in combination with having""" + + class Person(Base, fixtures.ComparableEntity): + __tablename__ = "people" + id = Column( + Integer, primary_key=True, test_needs_autoincrement=True + ) + name = Column(String(50)) + discriminator = Column("type", String(50)) + __mapper_args__ = {"polymorphic_on": discriminator} + + class Engineer(Person): + __mapper_args__ = {"polymorphic_identity": "engineer"} + primary_language = Column(String(50)) + + Base.metadata.create_all() + sess = create_session() + e1 = Engineer(name="Sean", primary_language="js") + sess.add(e1) + sess.flush() + sess.expunge_all() + eq_( + sess.query(Engineer) + .group_by(Engineer.id) + .having(Engineer.primary_language=="js") + .first(), + Engineer(name="Sean"), + ) + def test_single_cols_on_sub_base_of_joined(self): """test [ticket:3895]""" -- 2.47.3