From: Mike Bayer Date: Wed, 31 Oct 2012 18:30:47 +0000 (-0400) Subject: Fixed bug whereby the ".key" of a Column wasn't being X-Git-Tag: rel_0_8_0b2~71 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d30ab8495c9e16f7cf599da02ac8e333cc620b54;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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] --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 989cf69df7..e10780c83c 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -3,6 +3,18 @@ 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 diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py index 59964c364c..a09d3012e8 100644 --- a/lib/sqlalchemy/__init__.py +++ b/lib/sqlalchemy/__init__.py @@ -120,7 +120,7 @@ from .engine import create_engine, engine_from_config __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 diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 44072cd12b..6380cd86be 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -1145,7 +1145,7 @@ class Column(SchemaItem, expression.ColumnClause): 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) diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 84fe9a82ee..91f10cf3c1 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -4418,10 +4418,12 @@ class ColumnClause(Immutable, ColumnElement): 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 @@ -4490,7 +4492,7 @@ class TableClause(Immutable, FromClause): # 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): diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index 35d5a0b050..53c9018cde 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -125,6 +125,30 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled 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), @@ -151,6 +175,7 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled 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())