From: Mike Bayer Date: Wed, 30 Oct 2013 14:34:31 +0000 (-0400) Subject: - Fixed a regression introduced by :ticket:`2818` where the EXISTS X-Git-Tag: rel_0_8_4~42 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2576b5cdfb09fd1fb28e083e0a41f7596c6a1100;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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. --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index c859f82600..cce687af33 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -10,6 +10,16 @@ .. 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 diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 499bdeb4d7..28388b9696 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -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. diff --git a/test/orm/test_query.py b/test/orm/test_query.py index 30d32db962..6c1d97173a 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -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' )