From: Mike Bayer Date: Tue, 24 Apr 2012 17:04:38 +0000 (-0400) Subject: - [bug] column.label(None) now produces an X-Git-Tag: rel_0_8_0b1~461 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=503bddc879e12256fe8d94b39e675e44421f66a7;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [bug] column.label(None) now produces an anonymous label, instead of returning the column object itself, consistent with the behavior of label(column, None). [ticket:2168] --- diff --git a/CHANGES b/CHANGES index 4b01c4eebd..492f44d672 100644 --- a/CHANGES +++ b/CHANGES @@ -144,6 +144,11 @@ CHANGES "inspector" object as the first argument. [ticket:2418] + - [bug] column.label(None) now produces an + anonymous label, instead of returning the + column object itself, consistent with the behavior + of label(column, None). [ticket:2168] + - [bug] Removed warning when Index is created with no columns; while this might not be what the user intended, it is a valid use case diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index d50c3922a1..dda231e0c7 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -3240,8 +3240,9 @@ class _ColumnEntity(_QueryEntity): # can be located in the result even # if the expression's identity has been changed # due to adaption. - if not column._label: - column = column.label(None) + + if not column._label and not getattr(column, 'is_literal', False): + column = column.label(self._label_name) query._entities.append(self) diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 6147b1640a..a0f0bab6ca 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -4120,18 +4120,6 @@ class ColumnClause(_Immutable, ColumnElement): else: return name - def label(self, name): - # currently, anonymous labels don't occur for - # ColumnClause. The use at the moment - # is that they do not generate nicely for - # is_literal clauses. We would like to change - # this so that label(None) acts as would be expected. - # See [ticket:2168]. - if name is None: - return self - else: - return super(ColumnClause, self).label(name) - def _bind_param(self, operator, obj): return _BindParamClause(self.name, obj, diff --git a/test/orm/test_query.py b/test/orm/test_query.py index 96414f07a8..be0e1c3be2 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -1277,8 +1277,8 @@ class SetOpsTest(QueryTest, AssertsCompiledSQL): self.assert_compile( q3, "SELECT anon_1.users_id AS anon_1_users_id, anon_1.users_name AS anon_1_users_name," - " anon_1.anon_2 AS anon_1_anon_2 FROM (SELECT users.id AS users_id, users.name AS" - " users_name, :param_1 AS anon_2 FROM users UNION SELECT users.id AS users_id, " + " anon_1.param_1 AS anon_1_param_1 FROM (SELECT users.id AS users_id, users.name AS" + " users_name, :param_1 AS param_1 FROM users UNION SELECT users.id AS users_id, " "users.name AS users_name, 'y' FROM users) AS anon_1" ) @@ -1300,7 +1300,7 @@ class SetOpsTest(QueryTest, AssertsCompiledSQL): ['User', 'foo'] ) - for q in (q3.order_by(User.id, "anon_1_anon_2"), q6.order_by(User.id, "foo")): + for q in (q3.order_by(User.id, "anon_1_param_1"), q6.order_by(User.id, "foo")): eq_(q.all(), [ (User(id=7, name=u'jack'), u'x'), diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index e3508f77dc..66053b794f 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -545,19 +545,18 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled eq_(c1._label, "t1_c1") class AnonLabelTest(fixtures.TestBase): - """Test behaviors that we hope to change with [ticket:2168].""" + """Test behaviors fixed by [ticket:2168].""" def test_anon_labels_named_column(self): c1 = column('x') - # surprising - assert c1.label(None) is c1 - eq_(str(select([c1.label(None)])), "SELECT x") + assert c1.label(None) is not c1 + eq_(str(select([c1.label(None)])), "SELECT x AS x_1") def test_anon_labels_literal_column(self): c1 = literal_column('x') - assert c1.label(None) is c1 - eq_(str(select([c1.label(None)])), "SELECT x") + assert c1.label(None) is not c1 + eq_(str(select([c1.label(None)])), "SELECT x AS x_1") def test_anon_labels_func(self): c1 = func.count('*')