Commits

Mike Bayer committed eee219b

- 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.

Comments (0)

Files changed (3)

doc/build/changelog/changelog_08.rst

     :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
         :versions: 0.9.0b2

lib/sqlalchemy/orm/query.py

         .. 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.

test/orm/test_query.py

 
 
 class ExistsTest(QueryTest, AssertsCompiledSQL):
+    __dialect__ = 'default'
 
     def test_exists(self):
         User = self.classes.User
         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'
         )