From: Mike Bayer Date: Sat, 28 May 2011 17:28:38 +0000 (-0400) Subject: - Streamlined the process by which a Select X-Git-Tag: rel_0_7_1~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=736481e58f62841f3be9cb34f58f426fc52594b1;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Streamlined the process by which a Select determines what's in it's '.c' collection. Behaves identically, except that a raw ClauseList() passed to select([]) (which is not a documented case anyway) will now be expanded into its individual column elements instead of being ignored. --- diff --git a/CHANGES b/CHANGES index 7863daa8c8..a946f2cac6 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,18 @@ ======= CHANGES ======= +0.7.1 +===== + +- sql + - Streamlined the process by which a Select + determines what's in it's '.c' collection. + Behaves identically, except that a + raw ClauseList() passed to select([]) + (which is not a documented case anyway) will + now be expanded into its individual column + elements instead of being ignored. + 0.7.0 ======= - This section documents those changes from 0.7b4 diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index eb40e9d40d..0d98c89e5a 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -5058,19 +5058,11 @@ class Select(_SelectBase): self._froms = self._froms.union([fromclause]) - def __exportable_columns(self): - for column in self._raw_columns: - if isinstance(column, Selectable): - for co in column.columns: - yield co - elif isinstance(column, ColumnElement): - yield column - else: - continue def _populate_column_collection(self): - for c in self.__exportable_columns(): - c._make_proxy(self, name=self.use_labels and c._label or None) + for c in self.inner_columns: + if hasattr(c, '_make_proxy'): + c._make_proxy(self, name=self.use_labels and c._label or None) def self_group(self, against=None): """return a 'grouping' construct as per the ClauseElement diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index 47d81b8793..af11694dc3 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -319,6 +319,34 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled "SELECT c FROM (SELECT (SELECT (SELECT table1.col1 AS a FROM table1) AS b) AS c)" ) + def test_unusual_column_elements_text(self): + """test that .c excludes text().""" + + s = select([table1.c.col1, text("foo")]) + eq_( + list(s.c), + [s.c.col1] + ) + + def test_unusual_column_elements_clauselist(self): + """Test that raw ClauseList is expanded into .c.""" + + from sqlalchemy.sql.expression import ClauseList + s = select([table1.c.col1, ClauseList(table1.c.col2, table1.c.col3)]) + eq_( + list(s.c), + [s.c.col1, s.c.col2, s.c.col3] + ) + + def test_unusual_column_elements_boolean_clauselist(self): + """test that BooleanClauseList is placed as single element in .c.""" + + c2 = and_(table1.c.col2==5, table1.c.col3==4) + s = select([table1.c.col1, c2]) + eq_( + list(s.c), + [s.c.col1, s.corresponding_column(c2)] + ) class AnonLabelTest(fixtures.TestBase): """Test behaviors that we hope to change with [ticket:2168]."""