]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed regression from 0.8.3 as a result of :ticket:`2818`
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 22 Mar 2014 23:55:00 +0000 (19:55 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 22 Mar 2014 23:55:00 +0000 (19:55 -0400)
where :meth:`.Query.exists` wouldn't work on a query that only
had a :meth:`.Query.select_from` entry but no other entities.
re: #2818 fixes #2995

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

index a9cd75bae7fd0a2fd375bb60ca3f302baa3b422f..7616a3f107e8dcb73eddfb5f57129517e30e3eb4 100644 (file)
 .. changelog::
     :version: 0.8.6
 
+    .. change::
+        :tags: bug, orm
+        :tickets: 2995,
+        :versions: 0.9.4
+
+        Fixed regression from 0.8.3 as a result of :ticket:`2818`
+        where :meth:`.Query.exists` wouldn't work on a query that only
+        had a :meth:`.Query.select_from` entry but no other entities.
+
     .. change::
         :tags: bug, general
         :tickets: 2986
index 0f5b8bf88a32ccc62276e9eb5962911d3df56ae5..afcbf3500c696c2cb98103bb33a8e4ce26162f72 100644 (file)
@@ -2543,7 +2543,14 @@ class Query(object):
         .. versionadded:: 0.8.1
 
         """
-        return sql.exists(self.with_labels().statement.with_only_columns(['1']))
+
+        # .add_columns() for the case that we are a query().select_from(X),
+        # so that ".statement" can be produced (#2995) but also without
+        # omitting the FROM clause from a query(X) (#2818);
+        # .with_only_columns() after we have a core select() so that
+        # we get just "SELECT 1" without any entities.
+        return sql.exists(self.add_columns('1').with_labels().
+                                statement.with_only_columns(['1']))
 
     def count(self):
         """Return a count of rows this Query would return.
index 0564e5feabec34d6f7205dd9a0ca1b833d9c5a6e..312a8bc72a303b92e76766fb6b5d0fc9bdaafc35 100644 (file)
@@ -1798,6 +1798,17 @@ class ExistsTest(QueryTest, AssertsCompiledSQL):
             ') AS anon_1'
         )
 
+    def test_exists_w_select_from(self):
+        User = self.classes.User
+        sess = create_session()
+
+        q1 = sess.query().select_from(User).exists()
+        self.assert_compile(sess.query(q1),
+            'SELECT EXISTS ('
+                'SELECT 1 FROM users'
+            ') AS anon_1'
+        )
+
 
 class CountTest(QueryTest):
     def test_basic(self):