summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2021-03-07 16:32:19 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2021-03-07 16:32:19 +0000
commitc24bf520eb4b84c6a64a0f26485a79866118ad82 (patch)
tree806fe6eedcca3faa0147dc59b19229d6fd60f490 /lib/sqlalchemy
parent1edbe841bcb43d761f5084a2e77e8f37ee041c35 (diff)
parent8b8a4c373e1cec2203f73b1772704b9ded75c1fe (diff)
downloadsqlalchemy-c24bf520eb4b84c6a64a0f26485a79866118ad82.tar.gz
Merge "Ensure all Query statements compile w/ orm, fix test harness"
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/query.py10
-rw-r--r--lib/sqlalchemy/testing/assertions.py8
2 files changed, 13 insertions, 5 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index c444b557b..d685ac83e 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -440,6 +440,15 @@ class Query(
)
stmt.__dict__.pop("session", None)
+ # ensure the ORM context is used to compile the statement, even
+ # if it has no ORM entities. This is so ORM-only things like
+ # _legacy_joins are picked up that wouldn't be picked up by the
+ # Core statement context
+ if "compile_state_plugin" not in stmt._propagate_attrs:
+ stmt._propagate_attrs = stmt._propagate_attrs.union(
+ {"compile_state_plugin": "orm", "plugin_subject": None}
+ )
+
return stmt
def subquery(
@@ -2304,6 +2313,7 @@ class Query(
"is deprecated and will be removed in SQLAlchemy 2.0. "
"Please use individual join() calls per relationship."
)
+
self._legacy_setup_joins += joins_to_add
self.__dict__.pop("_last_joined_entity", None)
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py
index 81c74e7c1..289ac9a0a 100644
--- a/lib/sqlalchemy/testing/assertions.py
+++ b/lib/sqlalchemy/testing/assertions.py
@@ -445,11 +445,9 @@ class AssertsCompiledSQL(object):
from sqlalchemy import orm
if isinstance(clause, orm.Query):
- compile_state = clause._compile_state()
- compile_state.statement._label_style = (
- LABEL_STYLE_TABLENAME_PLUS_COL
- )
- clause = compile_state.statement
+ stmt = clause._statement_20()
+ stmt._label_style = LABEL_STYLE_TABLENAME_PLUS_COL
+ clause = stmt
if compile_kwargs:
kw["compile_kwargs"] = compile_kwargs