diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-03-23 22:05:22 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-03-24 12:35:53 -0400 |
| commit | da04aa577b6e539a6472df62ee39c4a51cca9dd9 (patch) | |
| tree | 7746c455c102e15397b11c565b302a5b81f19c51 /lib | |
| parent | 8acbc2624fb4b457e47fab93e6a44a1e37caeddc (diff) | |
| download | sqlalchemy-da04aa577b6e539a6472df62ee39c4a51cca9dd9.tar.gz | |
Fix boolean check in new path comparison logic
Fixed regression where a new error message that was supposed to raise when
attempting to link a relationship option to an AliasedClass without using
:meth:`.PropComparator.of_type` would instead raise an ``AttributeError``.
Note that in 1.3, it is no longer valid to create an option path from a
plain mapper relationship to an :class:`.AliasedClass` without using
:meth:`.PropComparator.of_type`.
Fixes: #4566
Change-Id: Ic547a1c8408e41aec66ef9644aac7f76f50dd064
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/orm/strategy_options.py | 20 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/util.py | 6 |
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py index 8a34771c7..912b6b550 100644 --- a/lib/sqlalchemy/orm/strategy_options.py +++ b/lib/sqlalchemy/orm/strategy_options.py @@ -227,7 +227,7 @@ class Load(Generative, MapperOption): if raiseerr: raise sa_exc.ArgumentError( 'Can\'t find property named "%s" on ' - "%s in this Query. " % (attr, ent) + "%s in this Query." % (attr, ent) ) else: return None @@ -236,6 +236,9 @@ class Load(Generative, MapperOption): path = path[attr] elif _is_mapped_class(attr): + # TODO: this does not appear to be a valid codepath. "attr" + # would never be a mapper. This block is present in 1.2 + # as well howver does not seem to be accessed in any tests. if not orm_util._entity_corresponds_to_use_path_impl( attr.parent, path[-1] ): @@ -255,7 +258,20 @@ class Load(Generative, MapperOption): if raiseerr: raise sa_exc.ArgumentError( 'Attribute "%s" does not ' - 'link from element "%s"' % (attr, path.entity) + 'link from element "%s".%s' + % ( + attr, + path.entity, + ( + " Did you mean to use " + "%s.of_type(%s)?" + % (path[-2], attr.class_.__name__) + if len(path) > 1 + and path.entity.is_mapper + and attr.parent.is_aliased_class + else "" + ), + ) ) else: return None diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index f9258895d..7b8edd349 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -1265,8 +1265,10 @@ def _entity_corresponds_to_use_path_impl(given, entity): return ( entity.is_aliased_class and not entity._use_mapper_path - and given is entity - or given in entity._with_polymorphic_entities + and ( + given is entity + or given in entity._with_polymorphic_entities + ) ) elif not entity.is_aliased_class: return given.common_parent(entity.mapper) |
