diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-04-24 13:04:38 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-04-24 13:04:38 -0400 |
| commit | 503bddc879e12256fe8d94b39e675e44421f66a7 (patch) | |
| tree | 88536f796a3e67fe168d83d296e60bdbea249586 | |
| parent | 71c00115747d2fb13423b0b18e728b402f117528 (diff) | |
| download | sqlalchemy-503bddc879e12256fe8d94b39e675e44421f66a7.tar.gz | |
- [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]
| -rw-r--r-- | CHANGES | 5 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 5 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/expression.py | 12 | ||||
| -rw-r--r-- | test/orm/test_query.py | 6 | ||||
| -rw-r--r-- | test/sql/test_selectable.py | 11 |
5 files changed, 16 insertions, 23 deletions
@@ -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 d50c3922a..dda231e0c 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 6147b1640..a0f0bab6c 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 96414f07a..be0e1c3be 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 e3508f77d..66053b794 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('*') |
