]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed a subtle bug involving column
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 27 Jun 2011 22:54:02 +0000 (18:54 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 27 Jun 2011 22:54:02 +0000 (18:54 -0400)
    correspondence in a selectable with the
    same column repeated.   Affects [ticket:2188].

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

diff --git a/CHANGES b/CHANGES
index c7695f488e716f690232da63d7966f09f7cb4ae1..9aaccb06744f1f8ffac728d1c6478dba826de84d 100644 (file)
--- 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()
index f78015ac2ed6fcdbf6018dca1203a394a4631d61..9dd7bd335956c622f502e9e0b282a7d5db85097e 100644 (file)
@@ -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
index ef87a68b9ec75f239e01a7b3a084b6fff6e6e94a..debdd0bb7d0d6912b041e63d647dfa6f925b7159 100644 (file)
@@ -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