]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug whereby with_only_columns() method of
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 21 Sep 2011 21:08:08 +0000 (17:08 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 21 Sep 2011 21:08:08 +0000 (17:08 -0400)
    Select would fail if a selectable were passed.
    [ticket:2270].  Also in 0.6.9.

CHANGES
lib/sqlalchemy/sql/expression.py
test/sql/test_selectable.py

diff --git a/CHANGES b/CHANGES
index 5b9ed4c96b2b5e409b2380b11776c5d225b3d05f..f31732702c51314594a995c78d8cc79c01ae6559 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -119,6 +119,10 @@ CHANGES
     such that the "froms" collection can be cleared
     and re-generated at any time.  [ticket:2261]
 
+  - Fixed bug whereby with_only_columns() method of
+    Select would fail if a selectable were passed.
+    [ticket:2270].  Also in 0.6.9.
+
 - schema
   - Added a slightly nicer __repr__() to SchemaItem
     classes.  Note the repr here can't fully support
index 84fcbd569561f850a04b46bf3311354c8ceea0ba..9a7f5e376af0ba6b5212e3f985919b371c8dafc5 100644 (file)
@@ -4610,11 +4610,13 @@ class Select(_SelectBase):
 
         """
         self._reset_exported()
-        self._raw_columns = [
-                isinstance(c, _ScalarSelect) and 
-                c.self_group(against=operators.comma_op) or c
-                for c in [_literal_as_column(c) for c in columns]
-            ]
+        rc = []
+        for c in columns:
+            c = _literal_as_column(c)
+            if isinstance(c, _ScalarSelect):
+                c = c.self_group(against=operators.comma_op)
+            rc.append(c)
+        self._raw_columns = rc
 
     @_generative
     def where(self, whereclause):
index 4bbcf61d286bd968a05eb8bd4bc10ad640ab8781..9a9fc0de98f0e66db825f4d35570b2860b957de6 100644 (file)
@@ -127,6 +127,14 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled
         sel3 = visitors.ReplacingCloningVisitor().traverse(sel2)
         assert sel3.corresponding_column(col) is sel3.c.foo
 
+    def test_with_only_generative(self):
+        s1 = table1.select().as_scalar()
+        self.assert_compile(
+            s1.with_only_columns([s1]),
+            "SELECT (SELECT table1.col1, table1.col2, "
+            "table1.col3, table1.colx FROM table1) AS anon_1"
+        )
+
 
     def test_select_on_table(self):
         sel = select([table1, table2], use_labels=True)