]> 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 23:31:21 +0000 (19:31 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 27 Jun 2011 23:31:21 +0000 (19:31 -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 eb44ebee267f07f7e856751ee727be71c7362288..1b2f8ccfd792019a9ff0fe6b4cb4e6e382eb7781 100644 (file)
--- 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,
index 30d713f2f0c64e88b5707732abe99a31f05eca0a..01d45bba59ad0ee6f78ab4eb004ed3c7041401ac 100644 (file)
@@ -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
index d67e721a0300bfdc149bb4e53bce65a45ba7f5ff..0febb27f6a21731b5545e15defac16793f2a0a7e 100644 (file)
@@ -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