]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixed Query.exists() method for the case, when query doesn't have any filters applied.
authorVladimir Magamedov <vladimir@magamedov.com>
Wed, 4 Sep 2013 08:43:40 +0000 (11:43 +0300)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 4 Sep 2013 15:45:14 +0000 (11:45 -0400)
doc/build/changelog/changelog_08.rst
doc/build/changelog/changelog_09.rst
lib/sqlalchemy/orm/query.py
test/orm/test_query.py

index 454b9ea2666ab7bc8932cab61f5af7fbb8680e75..10c2e5189f1a47cb961fdf7aee8c51fab04df729 100644 (file)
@@ -6,6 +6,13 @@
 .. changelog::
     :version: 0.8.3
 
+    .. change::
+        :tags: bug, orm
+        :tickets: 2818
+
+        Fixed bug where :meth:`.Query.exists` failed to work correctly
+        without any WHERE criterion.  Courtesy Vladimir Magamedov.
+
     .. change::
         :tags: bug, sql
         :tickets: 2811
index 59dfb52eb4179961e0daa61b3f13bfea4b8d9a1c..03cecff2ca744234ff4fc5c272947c3293d5834d 100644 (file)
@@ -6,6 +6,14 @@
 .. changelog::
     :version: 0.9.0
 
+    .. change::
+        :tags: bug, orm
+        :tickets: 2818
+
+        Fixed bug where :meth:`.Query.exists` failed to work correctly
+        without any WHERE criterion.  Courtesy Vladimir Magamedov.
+        Also in 0.8.3.
+
     .. change::
         :tags: bug, sql
         :tickets: 2811
index b71bfe08f2c451e841c8550d4bd10862c0ec26aa..d64575aec87ec7abe09b9e25bc4a7637ea417c01 100644 (file)
@@ -2494,7 +2494,7 @@ class Query(object):
         .. versionadded:: 0.8.1
 
         """
-        return sql.exists(self.with_entities('1').statement)
+        return sql.exists(self.statement.with_only_columns(['1']))
 
     def count(self):
         """Return a count of rows this Query would return.
index 0973dc357a92118c5f08ba26746c04ba076dcb65..7151ef0b60332a8fc372a5a2e2b2c36ace628729 100644 (file)
@@ -1730,8 +1730,17 @@ class ExistsTest(QueryTest, AssertsCompiledSQL):
     def test_exists(self):
         User = self.classes.User
         sess = create_session()
-        q1 = sess.query(User).filter(User.name == 'fred')
+
+        q1 = sess.query(User)
         self.assert_compile(sess.query(q1.exists()),
+            'SELECT EXISTS ('
+                'SELECT 1 FROM users'
+            ') AS anon_1',
+            dialect=default.DefaultDialect()
+        )
+
+        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',