]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Repair WithinGroup.get_children()
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 16 Jun 2017 13:58:03 +0000 (09:58 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 16 Jun 2017 13:58:03 +0000 (09:58 -0400)
Fixed AttributeError which would occur in :class:`.WithinGroup`
construct during an iteration of the structure.

Change-Id: I563882d93c8c32292463a605b636aa60c77e9406
Fixes: #4012
doc/build/changelog/changelog_11.rst
lib/sqlalchemy/sql/elements.py
test/sql/test_generative.py

index 612dda08a5494851e5ae52faa974417ad0baf0b7..071cf074e2669b9447823ef5eb2a41e76992b0cc 100644 (file)
 .. changelog::
     :version: 1.1.11
 
+    .. change:: 4012
+        :tags: bug, sql
+        :tickets: 4012
+        :versions: 1.2.0b1
+
+        Fixed AttributeError which would occur in :class:`.WithinGroup`
+        construct during an iteration of the structure.
+
     .. change:: 4005
         :tags: bug, postgresql
         :tickets: 4005
index 88c2949990d1c92c5a259401a377a6af7cb0ab74..46a8d2c35906189a32c15826eefe9163df7af01d 100644 (file)
@@ -3379,7 +3379,7 @@ class WithinGroup(ColumnElement):
 
     def get_children(self, **kwargs):
         return [c for c in
-                (self.func, self.order_by)
+                (self.element, self.order_by)
                 if c is not None]
 
     def _copy_internals(self, clone=_clone, **kw):
index 1a12a8b0e5dd7e8e25a7c4c19b2207c382606db3..9474560ff1762b320cb040e5a0b2adcc4425fe6c 100644 (file)
@@ -8,6 +8,7 @@ from sqlalchemy.testing import fixtures, AssertsExecutionResults, \
 from sqlalchemy import testing
 from sqlalchemy.sql.visitors import ClauseVisitor, CloningVisitor, \
     cloned_traverse, ReplacingCloningVisitor
+from sqlalchemy.sql import visitors
 from sqlalchemy import exc
 from sqlalchemy.sql import util as sql_util
 from sqlalchemy.testing import (eq_,
@@ -594,6 +595,15 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL):
         expr2 = CloningVisitor().traverse(expr)
         assert str(expr) == str(expr2)
 
+        assert expr in visitors.iterate(expr, {})
+
+    def test_within_group(self):
+        expr = func.row_number().within_group(t1.c.col1)
+        expr2 = CloningVisitor().traverse(expr)
+        assert str(expr) == str(expr2)
+
+        assert expr in visitors.iterate(expr, {})
+
     def test_funcfilter(self):
         expr = func.count(1).filter(t1.c.col1 > 1)
         expr2 = CloningVisitor().traverse(expr)