summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/context.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-08-29 10:43:36 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-08-29 23:42:18 -0400
commitb7f1fb5879606934abb54a8b75e4613339bc8f29 (patch)
tree0453b755103599d4e45d09aae2efbb520d39f083 /lib/sqlalchemy/orm/context.py
parent237969087f286451aee4647a4ff5e391fc2bd8aa (diff)
downloadsqlalchemy-b7f1fb5879606934abb54a8b75e4613339bc8f29.tar.gz
refine ruleset to determine when poly adaption should be used
Fixed regression appearing in the 1.4 series where a joined-inheritance query placed as a subquery within an enclosing query for that same entity would fail to render the JOIN correctly for the inner query. The issue manifested in two different ways prior and subsequent to version 1.4.18 (related issue #6595), in one case rendering JOIN twice, in the other losing the JOIN entirely. To resolve, the conditions under which "polymorphic loading" are applied have been scaled back to not be invoked for simple joined inheritance queries. Fixes: #8456 Change-Id: Ie4332fadb1dfc670cd31d098a6586a9f6976bcf7
Diffstat (limited to 'lib/sqlalchemy/orm/context.py')
-rw-r--r--lib/sqlalchemy/orm/context.py19
1 files changed, 6 insertions, 13 deletions
diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py
index b762908c5..ff0cdd680 100644
--- a/lib/sqlalchemy/orm/context.py
+++ b/lib/sqlalchemy/orm/context.py
@@ -490,6 +490,10 @@ class ORMCompileState(AbstractORMCompileState):
]
def _create_with_polymorphic_adapter(self, ext_info, selectable):
+ """given MapperEntity or ORMColumnEntity, setup polymorphic loading
+ if appropriate
+
+ """
if (
not ext_info.is_aliased_class
and ext_info.mapper.persist_selectable
@@ -2423,14 +2427,7 @@ class _MapperEntity(_QueryEntity):
self._with_polymorphic_mappers = ext_info.with_polymorphic_mappers
self._polymorphic_discriminator = ext_info.polymorphic_on
- if (
- mapper.with_polymorphic
- # controversy - only if inheriting mapper is also
- # polymorphic?
- # or (mapper.inherits and mapper.inherits.with_polymorphic)
- or mapper.inherits
- or mapper._requires_row_aliasing
- ):
+ if mapper._should_select_with_poly_adapter:
compile_state._create_with_polymorphic_adapter(
ext_info, self.selectable
)
@@ -2923,11 +2920,7 @@ class _ORMColumnEntity(_ColumnEntity):
self._extra_entities = (self.expr, self.column)
- if (
- mapper.with_polymorphic
- or mapper.inherits
- or mapper._requires_row_aliasing
- ):
+ if mapper._should_select_with_poly_adapter:
compile_state._create_with_polymorphic_adapter(
ezero, ezero.selectable
)