From: Mike Bayer Date: Fri, 16 Jun 2017 13:58:03 +0000 (-0400) Subject: Repair WithinGroup.get_children() X-Git-Tag: rel_1_2_0b1~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a314fcea8539133947d5ec8e42a6c86e30fdf9a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Repair WithinGroup.get_children() Fixed AttributeError which would occur in :class:`.WithinGroup` construct during an iteration of the structure. Change-Id: I563882d93c8c32292463a605b636aa60c77e9406 Fixes: #4012 --- diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 612dda08a5..071cf074e2 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 88c2949990..46a8d2c359 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 1a12a8b0e5..9474560ff1 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)