]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixes: #5781 - fix bug with having criteria with adapters 5782/head
authoresoh <sean.so.oh@gmail.com>
Fri, 18 Dec 2020 05:44:44 +0000 (21:44 -0800)
committeresoh <sean.so.oh@gmail.com>
Fri, 18 Dec 2020 05:44:44 +0000 (21:44 -0800)
lib/sqlalchemy/orm/context.py
test/orm/declarative/test_inheritance.py

index cd654ed3d6eefdc54c77a4dd6a9a4c6dff0a22dd..41b2146a3d66405e9695398f1cf53c69aa180d6d 100644 (file)
@@ -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
             )
 
index d8847ed40299dbe4c64f9f7d4b38bd07af8e06b6..6ae54bd7129af525bfaeecf0cf02a5e8d383b8cb 100644 (file)
@@ -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]"""