diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-10-23 19:24:54 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-10-23 19:24:54 -0400 |
| commit | bd1777426255648215328252795dff24dfd08616 (patch) | |
| tree | 3d539521f799315150bdc9e80a38063c050a5bbd /lib/sqlalchemy | |
| parent | bbf68345f4993245689b96cc6c6a50013afa3caa (diff) | |
| download | sqlalchemy-bd1777426255648215328252795dff24dfd08616.tar.gz | |
skip ad-hoc properties within subclass_load_via_in
Fixed issue where "selectin_polymorphic" loading for inheritance mappers
would not function correctly if the :param:`_orm.Mapper.polymorphic_on`
parameter referred to a SQL expression that was not directly mapped on the
class.
Fixes: #8704
Change-Id: I1b6be2650895fd18d2c804f6ba96de966d11041a
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 5d784498a..5d255c9ab 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -3432,6 +3432,13 @@ class Mapper( enable_opt = strategy_options.Load(entity) for prop in self.attrs: + + # skip prop keys that are not instrumented on the mapped class. + # this is primarily the "_sa_polymorphic_on" property that gets + # created for an ad-hoc polymorphic_on SQL expression, issue #8704 + if prop.key not in self.class_manager: + continue + if prop.parent is self or prop in keep_props: # "enable" options, to turn on the properties that we want to # load by default (subject to options from the query) @@ -3440,7 +3447,8 @@ class Mapper( enable_opt = enable_opt._set_generic_strategy( # convert string name to an attribute before passing - # to loader strategy + # to loader strategy. note this must be in terms + # of given entity, such as AliasedClass, etc. (getattr(entity.entity_namespace, prop.key),), dict(prop.strategy_key), _reconcile_to_other=True, @@ -3451,7 +3459,8 @@ class Mapper( # the options from the query to override them disable_opt = disable_opt._set_generic_strategy( # convert string name to an attribute before passing - # to loader strategy + # to loader strategy. note this must be in terms + # of given entity, such as AliasedClass, etc. (getattr(entity.entity_namespace, prop.key),), {"do_nothing": True}, _reconcile_to_other=False, |
