]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed a regression introduced by :ticket:`2818` where the EXISTS
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 30 Oct 2013 14:34:31 +0000 (10:34 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 30 Oct 2013 14:34:57 +0000 (10:34 -0400)
query being generated would produce a "columns being replaced"
warning for a statement with two same-named columns,
as the internal SELECT wouldn't have use_labels set.

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/orm/query.py
test/orm/test_query.py

index c859f826005e06bcb4e7750784c291c48710c16b..cce687af339a9d5f54f325de257804503350e942 100644 (file)
 .. changelog::
     :version: 0.8.4
 
+    .. change::
+        :tags: bug, orm
+        :tickets: 2818
+        :versions: 0.9.0b2
+
+        Fixed a regression introduced by :ticket:`2818` where the EXISTS
+        query being generated would produce a "columns being replaced"
+        warning for a statement with two same-named columns,
+        as the internal SELECT wouldn't have use_labels set.
+
     .. change::
         :tags: bug, postgresql
         :tickets: 2855
index 499bdeb4d7fb672e60e33d103d11c52d68fe0849..28388b9696dc88eba538f04eeea24e785ac15fef 100644 (file)
@@ -2492,7 +2492,7 @@ class Query(object):
         .. versionadded:: 0.8.1
 
         """
-        return sql.exists(self.statement.with_only_columns(['1']))
+        return sql.exists(self.with_labels().statement.with_only_columns(['1']))
 
     def count(self):
         """Return a count of rows this Query would return.
index 30d32db9620287776deffad0d92059d0030cf725..6c1d97173aa85fcd8060c8fbed8c79c4649c80d7 100644 (file)
@@ -1733,6 +1733,7 @@ class AggregateTest(QueryTest):
 
 
 class ExistsTest(QueryTest, AssertsCompiledSQL):
+    __dialect__ = 'default'
 
     def test_exists(self):
         User = self.classes.User
@@ -1742,16 +1743,27 @@ class ExistsTest(QueryTest, AssertsCompiledSQL):
         self.assert_compile(sess.query(q1.exists()),
             'SELECT EXISTS ('
                 'SELECT 1 FROM users'
-            ') AS anon_1',
-            dialect=default.DefaultDialect()
+            ') AS anon_1'
         )
 
         q2 = sess.query(User).filter(User.name == 'fred')
         self.assert_compile(sess.query(q2.exists()),
             'SELECT EXISTS ('
                 'SELECT 1 FROM users WHERE users.name = :name_1'
-            ') AS anon_1',
-            dialect=default.DefaultDialect()
+            ') AS anon_1'
+        )
+
+    def test_exists_col_warning(self):
+        User = self.classes.User
+        Address = self.classes.Address
+        sess = create_session()
+
+        q1 = sess.query(User, Address).filter(User.id == Address.user_id)
+        self.assert_compile(sess.query(q1.exists()),
+            'SELECT EXISTS ('
+                'SELECT 1 FROM users, addresses '
+                'WHERE users.id = addresses.user_id'
+            ') AS anon_1'
         )