diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-01-06 21:06:10 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-01-07 10:50:02 -0500 |
| commit | 2734439fff953a7bb8aecdedb5f851441b5122e9 (patch) | |
| tree | c56e1f1e087f8ecdb89fea6c78f80731d947895b /lib/sqlalchemy | |
| parent | 84cb9d1f0a3f91fb5e3d4ece78b9ef94d1e5d826 (diff) | |
| download | sqlalchemy-2734439fff953a7bb8aecdedb5f851441b5122e9.tar.gz | |
Set use_mapper_path=True for with_poly subentities
Fixed regression in joined eager loading introduced in 1.3.0b3 via
:ticket:`4468` where the ability to create a joined option across a
:func:`.with_polymorphic` into a polymorphic subclass using
:meth:`.RelationshipProperty.of_type` and then further along regular mapped
relationships would fail as the polymorphic subclass would not add itself
to the load path in a way that could be located by the loader strategy. A
tweak has been made to resolve this scenario.
Fixes: #5082
Change-Id: I1c7b8d70ed94436c655e433bf34394b13d384c35
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/path_registry.py | 5 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/strategy_options.py | 1 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/util.py | 2 |
3 files changed, 6 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/path_registry.py b/lib/sqlalchemy/orm/path_registry.py index f860cc8fe..1de54251c 100644 --- a/lib/sqlalchemy/orm/path_registry.py +++ b/lib/sqlalchemy/orm/path_registry.py @@ -255,7 +255,10 @@ class PropRegistry(PathRegistry): and prop.parent in insp.with_polymorphic_mappers ): subclass_entity = parent[-1]._entity_for_mapper(prop.parent) - parent = parent.parent[subclass_entity] + if subclass_entity._use_mapper_path: + parent = parent.parent[subclass_entity.mapper] + else: + parent = parent.parent[subclass_entity] self.prop = prop self.parent = parent diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py index 9cc9cd157..b123ecc5d 100644 --- a/lib/sqlalchemy/orm/strategy_options.py +++ b/lib/sqlalchemy/orm/strategy_options.py @@ -312,6 +312,7 @@ class Load(HasCacheKey, Generative, MapperOption): existing = path.entity_path[prop].get( self.context, "path_with_polymorphic" ) + if not ext_info.is_aliased_class: ac = orm_util.with_polymorphic( ext_info.mapper.base_mapper, diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index ccadeeaac..3a82de781 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -606,7 +606,7 @@ class AliasedInsp(sql_base.HasCacheKey, InspectionAttr): selectable, base_alias=self, adapt_on_names=adapt_on_names, - use_mapper_path=_use_mapper_path, + use_mapper_path=True, ) setattr(self.entity, poly.class_.__name__, ent) |
