]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Use consistent method signature for Alias.self_group()
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 16 Mar 2017 21:28:41 +0000 (17:28 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Apr 2017 16:14:33 +0000 (12:14 -0400)
Fixed bug where the use of an :class:`.Alias` object in a column
context would raise an argument error when it tried to group itself
into a parenthesized expression.   Using :class:`.Alias` in this way
is not yet a fully supported API, however it applies to some end-user
recipes and may have a more prominent role in support of some
future Postgresql features.

Change-Id: I81717e30416e0350f08d1e022c3d84656e0a9735
Fixes: #3939
doc/build/changelog/changelog_12.rst
lib/sqlalchemy/sql/selectable.py
test/sql/test_selectable.py

index 9fd4c1936a64819bbb1bfc74ce04a811687c931e..1d66adc8ef1dd7af4a0c8e18e3b0cbae0e43c4b6 100644 (file)
 
             :ref:`change_3919`
 
+    .. change:: 3939
+        :tags: bug, sql
+        :tickets: 3939
+
+        Fixed bug where the use of an :class:`.Alias` object in a column
+        context would raise an argument error when it tried to group itself
+        into a parenthesized expression.   Using :class:`.Alias` in this way
+        is not yet a fully supported API, however it applies to some end-user
+        recipes and may have a more prominent role in support of some
+        future Postgresql features.
+
     .. change:: 3366
         :tags: bug, orm
         :tickets: 3366
index b69d667c6302b09d7188f1432eb0360c6f97bf1a..9db1e0844b9b539c79d2e8cf1b2844f00f5e1a02 100644 (file)
@@ -1241,13 +1241,13 @@ class Alias(FromClause):
                                                     or 'anon'))
         self.name = name
 
-    def self_group(self, target=None):
-        if isinstance(target, CompoundSelect) and \
+    def self_group(self, against=None):
+        if isinstance(against, CompoundSelect) and \
             isinstance(self.original, Select) and \
                 self.original._needs_parens_for_grouping():
             return FromGrouping(self)
 
-        return super(Alias, self).self_group(target)
+        return super(Alias, self).self_group(against=against)
 
     @property
     def description(self):
@@ -2269,7 +2269,7 @@ class CompoundSelect(GenerativeSelect):
                      n + 1, len(s.c._all_columns))
                 )
 
-            self.selects.append(s.self_group(self))
+            self.selects.append(s.self_group(against=self))
 
         GenerativeSelect.__init__(self, **kwargs)
 
index d38ee0e8a5db7c9873004cda727ccd9b2626537d..0cbaf33ea7ad3e657b9515399301c39989a2f22a 100644 (file)
@@ -333,6 +333,20 @@ class SelectableTest(
         criterion = a.c.col1 == table2.c.col2
         self.assert_(criterion.compare(j.onclause))
 
+    def test_alias_handles_column_context(self):
+        # not quite a use case yet but this is expected to become
+        # prominent w/ Postgresql's tuple functions
+
+        stmt = select([table1.c.col1, table1.c.col2])
+        a = stmt.alias('a')
+        self.assert_compile(
+            select([func.foo(a)]),
+            "SELECT foo(SELECT table1.col1, table1.col2 FROM table1) "
+            "AS foo_1 FROM "
+            "(SELECT table1.col1 AS col1, table1.col2 AS col2 FROM table1) "
+            "AS a"
+        )
+
     def test_union(self):
 
         # tests that we can correspond a column in a Select statement