From: Mike Bayer Date: Wed, 21 Sep 2011 21:08:08 +0000 (-0400) Subject: - Fixed bug whereby with_only_columns() method of X-Git-Tag: rel_0_7_3~40 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9d775a4cd4b8f66baa0f0256059fd547894f0813;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug whereby with_only_columns() method of Select would fail if a selectable were passed. [ticket:2270]. Also in 0.6.9. --- diff --git a/CHANGES b/CHANGES index 5b9ed4c96b..f31732702c 100644 --- 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 diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 84fcbd5695..9a7f5e376a 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -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): diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index 4bbcf61d28..9a9fc0de98 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -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)