From 595fcc4aa03afc0e5341609d659c486f55a7cc4f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 16 Jun 2012 19:05:37 -0400 Subject: [PATCH] - [bug] Fixed bug whereby append_column() wouldn't function correctly on a cloned select() construct, courtesy Gunnlaugur Por Briem. [ticket:2482] --- CHANGES | 5 +++++ lib/sqlalchemy/sql/expression.py | 4 ++-- test/sql/test_selectable.py | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 63d8c1162d..16bbdd7022 100644 --- a/CHANGES +++ b/CHANGES @@ -49,6 +49,11 @@ CHANGES compound expressions, courtesy btbuilder. [ticket:2490] + - [bug] Fixed bug whereby append_column() + wouldn't function correctly on a cloned + select() construct, courtesy + Gunnlaugur Þór Briem. [ticket:2482] + - engine - [bug] Fixed memory leak in C version of result proxy whereby DBAPIs which don't deliver diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index fbead90b3f..b308a7b05a 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -2172,7 +2172,7 @@ class ColumnElement(ClauseElement, _CompareMixin): co.proxies = [self] if selectable._is_clone_of is not None: co._is_clone_of = \ - selectable._is_clone_of.columns[key] + selectable._is_clone_of.columns.get(key) selectable._columns[key] = co return co @@ -4138,7 +4138,7 @@ class ColumnClause(_Immutable, ColumnElement): c.proxies = [self] if selectable._is_clone_of is not None: c._is_clone_of = \ - selectable._is_clone_of.columns[c.name] + selectable._is_clone_of.columns.get(c.name) if attach: selectable._columns[c.name] = c diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index bbb9131a52..d5cf724e67 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -138,6 +138,13 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled assert j2.corresponding_column(table1.c.col1) \ is j2.c.table1_col1 + def test_clone_append_column(self): + sel = select([literal_column('1').label('a')]) + cloned = visitors.ReplacingCloningVisitor().traverse(sel) + cloned.append_column(literal_column('2').label('b')) + cloned.append_column(func.foo()) + eq_(cloned.c.keys(), ['a', 'b', 'foo()']) + def test_against_cloned_non_table(self): # test that corresponding column digs across # clone boundaries with anonymous labeled elements -- 2.47.2