From: Mike Bayer Date: Mon, 27 Jun 2011 22:54:02 +0000 (-0400) Subject: - Fixed a subtle bug involving column X-Git-Tag: rel_0_7_2~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63dbed1fd7421fd4f5cbf0bb2773f7faa8359651;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed a subtle bug involving column correspondence in a selectable with the same column repeated. Affects [ticket:2188]. --- diff --git a/CHANGES b/CHANGES index c7695f488e..9aaccb0674 100644 --- a/CHANGES +++ b/CHANGES @@ -29,6 +29,11 @@ CHANGES after from_statement() were called. [ticket:2199]. Also in 0.6.9. +- sql + - Fixed a subtle bug involving column + correspondence in a selectable with the + same column repeated. Affects [ticket:2188]. + - engine - Use urllib.parse_qsl() in Python 2.6 and above, no deprecation warning about cgi.parse_qsl() diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index f78015ac2e..9dd7bd3359 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -2144,6 +2144,10 @@ class ColumnCollection(util.OrderedProperties): 'use_labels for select() statements.' % (key, getattr(existing, 'table', None))) self._all_cols.remove(existing) + # pop out memoized proxy_set as this + # operation may very well be occurring + # in a _make_proxy operation + value.__dict__.pop('proxy_set', None) self._all_cols.add(value) self._data[key] = value @@ -2328,7 +2332,6 @@ class FromClause(Selectable): """ # dont dig around if the column is locally present - if self.c.contains_column(column): return column col, intersect = None, None @@ -3873,6 +3876,7 @@ class ColumnClause(_Immutable, ColumnElement): is_literal=is_literal ) c.proxies = [self] + if attach: selectable._columns[c.name] = c return c diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index ef87a68b9e..debdd0bb7d 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -47,6 +47,24 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled assert s.corresponding_column(s.c.col1) is s.c.col1 assert s.corresponding_column(s.c.c1) is s.c.c1 + def test_labeled_subquery_twice(self): + scalar_select = select([table1.c.col1]).label('foo') + + s1 = select([scalar_select]) + s2 = select([scalar_select, scalar_select]) + + eq_( + s1.c.foo.proxy_set, + set([s1.c.foo, scalar_select, scalar_select.element, table1.c.col1]) + ) + eq_( + s2.c.foo.proxy_set, + set([s2.c.foo, scalar_select, scalar_select.element, table1.c.col1]) + ) + + assert s1.corresponding_column(scalar_select) is s1.c.foo + assert s2.corresponding_column(scalar_select) is s2.c.foo + def test_direct_correspondence_on_labels(self): # this test depends on labels being part # of the proxy set to get the right result