]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] column.label(None) now produces an
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Apr 2012 17:04:38 +0000 (13:04 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Apr 2012 17:04:38 +0000 (13:04 -0400)
anonymous label, instead of returning the
column object itself, consistent with the behavior
of label(column, None).  [ticket:2168]

CHANGES
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/sql/expression.py
test/orm/test_query.py
test/sql/test_selectable.py

diff --git a/CHANGES b/CHANGES
index 4b01c4eebdf46c856880a781b712b95b05dbddf4..492f44d6725f9e197c4c7cb4db75646a86cd54c4 100644 (file)
--- 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 
index d50c3922a156b91c6c62a78d7546cc21e9cacfac..dda231e0c7f811c4509b2596e5a87a4effc4f6cf 100644 (file)
@@ -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)
 
index 6147b1640ab2c09d3db7ace515149665671115ee..a0f0bab6cac6b3fd7a2044694ba8fd1dc54fa162 100644 (file)
@@ -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,
index 96414f07a8f75982c6c019aec570d4c3a22e6abb..be0e1c3be267168276cbcb9cf4266fe3b1a1b509 100644 (file)
@@ -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'), 
index e3508f77dcf9e93b0b1a1b8ae844ced7642386ed..66053b794f41c4cac126c54a3c4f7cd89fc699d4 100644 (file)
@@ -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('*')