Commits

Mike Bayer committed db72b8f

Fixed bug whereby the ".key" of a Column wasn't being
used when producing a "proxy" of the column against
a selectable. This probably didn't occur in 0.7
since 0.7 doesn't respect the ".key" in a wider
range of scenarios. [ticket:2597]

Comments (0)

Files changed (5)

doc/build/changelog/changelog_08.rst

 0.8 Changelog
 ==============
 
+.. changelog::
+    :version: 0.8.0b2
+
+    .. change::
+        :tags: sql, bug
+        :tickets: 2597
+
+        Fixed bug whereby the ".key" of a Column wasn't being
+        used when producing a "proxy" of the column against
+        a selectable.   This probably didn't occur in 0.7
+        since 0.7 doesn't respect the ".key" in a wider
+        range of scenarios.
 
 .. changelog::
     :version: 0.8.0b1

lib/sqlalchemy/__init__.py

 __all__ = sorted(name for name, obj in locals().items()
                  if not (name.startswith('_') or _inspect.ismodule(obj)))
 
-__version__ = '0.8.0b1'
+__version__ = '0.8.0b2'
 
 del _inspect, sys
 

lib/sqlalchemy/schema.py

         c.table = selectable
         selectable._columns.add(c)
         if selectable._is_clone_of is not None:
-            c._is_clone_of = selectable._is_clone_of.columns[c.name]
+            c._is_clone_of = selectable._is_clone_of.columns[c.key]
         if self.primary_key:
             selectable.primary_key.add(c)
         c.dispatch.after_parent_attach(c, selectable)

lib/sqlalchemy/sql/expression.py

                     type_=self.type,
                     is_literal=is_literal
                 )
+        if name is None:
+            c.key = self.key
         c._proxies = [self]
         if selectable._is_clone_of is not None:
             c._is_clone_of = \
-                selectable._is_clone_of.columns.get(c.name)
+                selectable._is_clone_of.columns.get(c.key)
 
         if attach:
             selectable._columns[c.key] = c
         # end Py2K
 
     def append_column(self, c):
-        self._columns[c.name] = c
+        self._columns[c.key] = c
         c.table = self
 
     def get_children(self, column_collections=True, **kwargs):

test/sql/test_selectable.py

         assert sel2.corresponding_column(keyed.c.coly) is sel2.c.keyed_coly
         assert sel2.corresponding_column(keyed.c.z) is sel2.c.keyed_z
 
+    def test_keyed_c_collection_upper(self):
+        c = Column('foo', Integer, key='bar')
+        t = Table('t', MetaData(), c)
+        is_(t.c.bar, c)
+
+    def test_keyed_c_collection_lower(self):
+        c = column('foo')
+        c.key = 'bar'
+        t = table('t', c)
+        is_(t.c.bar, c)
+
+    def test_clone_c_proxy_key_upper(self):
+        c = Column('foo', Integer, key='bar')
+        t = Table('t', MetaData(), c)
+        s = select([t])._clone()
+        assert c in s.c.bar.proxy_set
+
+    def test_clone_c_proxy_key_lower(self):
+        c = column('foo')
+        c.key = 'bar'
+        t = table('t', c)
+        s = select([t])._clone()
+        assert c in s.c.bar.proxy_set
+
     def test_distance_on_aliases(self):
         a1 = table1.alias('a1')
         for s in (select([a1, table1], use_labels=True),
 
     def test_clone_append_column(self):
         sel = select([literal_column('1').label('a')])
+        eq_(sel.c.keys(), ['a'])
         cloned = visitors.ReplacingCloningVisitor().traverse(sel)
         cloned.append_column(literal_column('2').label('b'))
         cloned.append_column(func.foo())