summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2019-03-25 19:09:58 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2019-03-25 19:09:58 +0000
commit47ee0e2e0f3db7c1e42a23c38e2d0b5ed5f0b91c (patch)
treed0fe5c3f33fe45dd846308815cdb5973de5c1357 /lib
parenta31da95e002e34d639daef27d972eb364a1ebd13 (diff)
parentda04aa577b6e539a6472df62ee39c4a51cca9dd9 (diff)
downloadsqlalchemy-47ee0e2e0f3db7c1e42a23c38e2d0b5ed5f0b91c.tar.gz
Merge "Fix boolean check in new path comparison logic"
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/orm/strategy_options.py20
-rw-r--r--lib/sqlalchemy/orm/util.py6
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)