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
--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 4428
+
+ 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.
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
User.id == Address.user_id,
)
+ def test_on_clause_no_right_side_two(self):
+ User = self.classes.User
+ Address = self.classes.Address
+ sess = create_session()
+
+ right = Address.user_id
+
+ assert_raises_message(
+ sa_exc.ArgumentError,
+ "Join target %s does not refer to a mapped entity" % right,
+ sess.query(User).join,
+ Address.user_id,
+ )
+
def test_select_from(self):
"""Test that the left edge of the join can be set reliably with
select_from()."""