You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Migrated issue, originally created by Michael Bayer (@zzzeek)
e.g.
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 272fed3e23..c623f10a95 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -514,7 +514,7 @@ class Query(object):
# TODO: there's no tests covering effects of
# the annotation not being there
- return stmt._annotate({'no_replacement_traverse': True})
+ return stmt
def subquery(self, name=None, with_labels=False, reduce_columns=False):
"""return the full SELECT statement represented by
here is a confusing effect of it being there:
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class MyTable(Base):
__tablename__ = 'my_table'
score = Column(Integer, primary_key=True)
my_alias = aliased(MyTable, name="my_alias")
s = Session()
query_2 = s.query(MyTable).union(s.query(MyTable))
query_2 = query_2.filter(MyTable.score > 5)
stmt1 = exists().where(my_alias.score > MyTable.score)
stmt2 = s.query(my_alias).filter(my_alias.score > MyTable.score).exists()
print(query_2.add_column(stmt1))
print(query_2.add_column(stmt2))
# correct:
SELECT anon_1.my_table_score AS anon_1_my_table_score, EXISTS (SELECT *
FROM my_table AS my_alias
WHERE my_alias.score > anon_1.my_table_score) AS anon_2
FROM (SELECT my_table.score AS my_table_score
FROM my_table UNION SELECT my_table.score AS my_table_score
FROM my_table) AS anon_1
WHERE anon_1.my_table_score > :score_1
# incorrect:
SELECT anon_1.my_table_score AS anon_1_my_table_score, EXISTS (SELECT 1
FROM my_table AS my_alias, my_table
WHERE my_alias.score > my_table.score) AS anon_2
FROM (SELECT my_table.score AS my_table_score
FROM my_table UNION SELECT my_table.score AS my_table_score
FROM my_table) AS anon_1
WHERE anon_1.my_table_score > :score_1
The text was updated successfully, but these errors were encountered:
Fixed long-standing issue in :class:.Query where a scalar subquery such
as produced by :meth:.Query.exists, :meth:.Query.as_scalar and other
derivations from :attr:.Query.statement would not correctly be adapted
when used in a new :class:.Query that required entity adaptation, such as
when the query were turned into a union, or a from_self(), etc. The change
removes the "no adaptation" annotation from the :func:.select object
produced by the :attr:.Query.statement accessor.
Migrated issue, originally created by Michael Bayer (@zzzeek)
e.g.
here is a confusing effect of it being there:
The text was updated successfully, but these errors were encountered: