diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-10-31 14:30:47 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-10-31 14:30:47 -0400 |
commit | d30ab8495c9e16f7cf599da02ac8e333cc620b54 (patch) | |
tree | 1f6cee48de9a8babcdcb6cd5e49ffc5d597a06d8 | |
parent | f0a9d39634d214672ab5171c7b8178abf2cbea94 (diff) | |
download | sqlalchemy-d30ab8495c9e16f7cf599da02ac8e333cc620b54.tar.gz |
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]
-rw-r--r-- | doc/build/changelog/changelog_08.rst | 12 | ||||
-rw-r--r-- | lib/sqlalchemy/__init__.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/schema.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/expression.py | 6 | ||||
-rw-r--r-- | test/sql/test_selectable.py | 25 |
5 files changed, 43 insertions, 4 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 989cf69df..e10780c83 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 59964c364..a09d3012e 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 44072cd12..6380cd86b 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 84fe9a82e..91f10cf3c 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 35d5a0b05..53c9018cd 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()) |