summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/context.py
diff options
context:
space:
mode:
authorRamonWill <ramonwilliams@hotmail.co.uk>2020-08-24 20:14:15 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-08-31 19:01:15 -0400
commit17090c004e19afab35c837bf880ea5b328e1fb56 (patch)
tree7c938e4f1b5e3ccbbe1081806509102430a0e2e9 /lib/sqlalchemy/orm/context.py
parentc3d74b3bef84f630993f307012003832cec232e7 (diff)
downloadsqlalchemy-17090c004e19afab35c837bf880ea5b328e1fb56.tar.gz
Provide a more detailed error message for Query.join()
An :class:`.ArgumentError` with more detail is now raised if the target parameter for :meth:`_query.Query.join` is set to an unmapped object. Prior to this change a less detailed ``AttributeError`` was raised. Pull request courtesy Ramon Williams. Fixes: #4428 Closes: #5452 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5452 Pull-request-sha: b148df547037e9a254fe331eff8e922c78426261 Change-Id: I873453d1fdb651178216aac698baac63ae5a94e8
Diffstat (limited to 'lib/sqlalchemy/orm/context.py')
-rw-r--r--lib/sqlalchemy/orm/context.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py
index 0868fb29b..d9e334d45 100644
--- a/lib/sqlalchemy/orm/context.py
+++ b/lib/sqlalchemy/orm/context.py
@@ -1170,7 +1170,18 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
if of_type:
right = of_type
else:
- right = onclause.property.entity
+ right = onclause.property
+
+ try:
+ right = right.entity
+ except AttributeError as err:
+ util.raise_(
+ sa_exc.ArgumentError(
+ "Join target %s does not refer to a "
+ "mapped entity" % right
+ ),
+ replace_context=err,
+ )
left = onclause._parententity
@@ -1312,7 +1323,18 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
if of_type:
right = of_type
else:
- right = onclause.property.entity
+ right = onclause.property
+
+ try:
+ right = right.entity
+ except AttributeError as err:
+ util.raise_(
+ sa_exc.ArgumentError(
+ "Join target %s does not refer to a "
+ "mapped entity" % right
+ ),
+ replace_context=err,
+ )
left = onclause._parententity