]> 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:28:12 +0000 (17:28 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 21 Sep 2011 21:28:12 +0000 (17:28 -0400)
    Select would fail if a selectable were passed.
    [ticket:2270].   However, the FROM behavior is
    still incorrect here, so you need 0.7 in
    any case for this use case to be usable.

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

diff --git a/CHANGES b/CHANGES
index 98a34e9d268d9b2cc8731e18e341166fdee17f2a..6a53e9d057d4b851e324bff9897e147ececbc9ab 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -69,6 +69,12 @@ CHANGES
     when used with certain dialects.  This
     bug is not in 0.7.
 
+  - Fixed bug whereby with_only_columns() method of
+    Select would fail if a selectable were passed.
+    [ticket:2270].   However, the FROM behavior is 
+    still incorrect here, so you need 0.7 in 
+    any case for this use case to be usable.
+
 - schema
   - Added an informative error message when 
     ForeignKeyConstraint refers to a column name in 
index 0035b57cd584b3d3f769c60f357191eb0745db6c..8df45d158022318f12a3d1264c961569859542e4 100644 (file)
@@ -4267,12 +4267,13 @@ class Select(_SelectBaseMixin, FromClause):
             with the given columns.
 
         """
-
-        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 dd0bf5275633783c51f709f8fd499578a0b82f3f..4209e33288d8e2c96aba33f71c89c1115b04a277 100644 (file)
@@ -125,6 +125,18 @@ class SelectableTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL):
         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()
+        s2 = table1.select().as_scalar()
+        self.assert_compile(
+            s1.with_only_columns([s2]),
+            # this is the wrong SQL - 0.7 does it correctly.
+            # but the test here at the moment is just that with_only_columns()
+            # doesn't try to evaluate the selectable as a boolean.
+            "SELECT (SELECT table1.col1, table1.col2, "
+            "table1.col3, table1.colx FROM table1) AS anon_1 FROM table1"
+        )
+
 
     def test_select_on_table(self):
         sel = select([table1, table2], use_labels=True)