From: Mike Bayer Date: Mon, 27 Jun 2011 23:31:21 +0000 (-0400) Subject: - Fixed a subtle bug involving column X-Git-Tag: rel_0_6_9~54 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0ef1ac8d43f870ee084624fc554bee8408ef934b;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 eb44ebee26..1b2f8ccfd7 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,11 @@ CHANGES after from_statement() were called. [ticket:2199]. +- sql + - Fixed a subtle bug involving column + correspondence in a selectable with the + same column repeated. Affects [ticket:2188]. + - oracle - Added ORA-00028 to disconnect codes, use cx_oracle _Error.code to get at the code, diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 30d713f2f0..01d45bba59 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -2116,6 +2116,11 @@ class ColumnCollection(util.OrderedProperties): 'another column with the same key. Consider ' 'use_labels for select() statements.' % (key, getattr(existing, 'table', None))) + # pop out memoized proxy_set as this + # operation may very well be occurring + # in a _make_proxy operation + value.__dict__.pop('proxy_set', None) + util.OrderedProperties.__setitem__(self, key, value) def remove(self, column): @@ -2279,7 +2284,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 @@ -3646,6 +3650,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 d67e721a03..0febb27f6a 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -45,6 +45,24 @@ class SelectableTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL): 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