summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/query.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-02-11 14:05:49 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-02-11 18:25:52 -0500
commit553ac45aae5712e64a5380ba1fa1c6028acf5f39 (patch)
tree1a165d582d7bfc1fb78f485f31f8b26d9a35eb10 /lib/sqlalchemy/orm/query.py
parent89dc4562adb38367ee5fabbcc04ee44968af4906 (diff)
downloadsqlalchemy-553ac45aae5712e64a5380ba1fa1c6028acf5f39.tar.gz
Apply consistent labeling for all future style ORM queries
Fixed issue in new 1.4/2.0 style ORM queries where a statement-level label style would not be preserved in the keys used by result rows; this has been applied to all combinations of Core/ORM columns / session vs. connection etc. so that the linkage from statement to result row is the same in all cases. also repairs a cache key bug where query.from_statement() vs. select().from_statement() would not be disambiguated; the compile options were not included in the cache key for FromStatement. Fixes: #5933 Change-Id: I22f6cf0f0b3360e55299cdcb2452cead2b2458ea
Diffstat (limited to 'lib/sqlalchemy/orm/query.py')
-rw-r--r--lib/sqlalchemy/orm/query.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index d36818254..30cb9e730 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -30,6 +30,7 @@ from .base import _assertions
from .context import _column_descriptions
from .context import _legacy_determine_last_joined_entity
from .context import _legacy_filter_by_entity_zero
+from .context import LABEL_STYLE_LEGACY_ORM
from .context import ORMCompileState
from .context import ORMFromStatementCompileState
from .context import QueryContext
@@ -59,7 +60,6 @@ from ..sql.selectable import ForUpdateArg
from ..sql.selectable import HasHints
from ..sql.selectable import HasPrefixes
from ..sql.selectable import HasSuffixes
-from ..sql.selectable import LABEL_STYLE_NONE
from ..sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
from ..sql.selectable import SelectStatementGrouping
from ..sql.visitors import InternalTraversal
@@ -119,7 +119,7 @@ class Query(
_from_obj = ()
_setup_joins = ()
_legacy_setup_joins = ()
- _label_style = LABEL_STYLE_NONE
+ _label_style = LABEL_STYLE_LEGACY_ORM
_compile_options = ORMCompileState.default_compile_options
@@ -2825,7 +2825,7 @@ class Query(
"""
- return _column_descriptions(self)
+ return _column_descriptions(self, legacy=True)
def instances(self, result_proxy, context=None):
"""Return an ORM result given a :class:`_engine.CursorResult` and
@@ -3199,6 +3199,10 @@ class FromStatement(SelectStatementGrouping, Executable):
("element", InternalTraversal.dp_clauseelement),
] + Executable._executable_traverse_internals
+ _cache_key_traversal = _traverse_internals + [
+ ("_compile_options", InternalTraversal.dp_has_cache_key)
+ ]
+
def __init__(self, entities, element):
self._raw_columns = [
coercions.expect(