summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-06-16 09:58:03 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-06-16 09:58:03 -0400
commit3a314fcea8539133947d5ec8e42a6c86e30fdf9a (patch)
treed4c7b8502ea836d4f6ecac34216fdfbf48bf0e7a
parent7af05fcc9387cea4172cc35eb6a198776488f90d (diff)
downloadsqlalchemy-3a314fcea8539133947d5ec8e42a6c86e30fdf9a.tar.gz
Repair WithinGroup.get_children()
Fixed AttributeError which would occur in :class:`.WithinGroup` construct during an iteration of the structure. Change-Id: I563882d93c8c32292463a605b636aa60c77e9406 Fixes: #4012
-rw-r--r--doc/build/changelog/changelog_11.rst8
-rw-r--r--lib/sqlalchemy/sql/elements.py2
-rw-r--r--test/sql/test_generative.py10
3 files changed, 19 insertions, 1 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst
index 612dda08a..071cf074e 100644
--- a/doc/build/changelog/changelog_11.rst
+++ b/doc/build/changelog/changelog_11.rst
@@ -21,6 +21,14 @@
.. 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
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index 88c294999..46a8d2c35 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -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):
diff --git a/test/sql/test_generative.py b/test/sql/test_generative.py
index 1a12a8b0e..9474560ff 100644
--- a/test/sql/test_generative.py
+++ b/test/sql/test_generative.py
@@ -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)