mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-18 22:52:01 -04:00
Provide 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: b148df5470
Change-Id: I873453d1fdb651178216aac698baac63ae5a94e8
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
.. 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.
|
||||
@@ -2512,7 +2512,18 @@ class Query(object):
|
||||
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
|
||||
|
||||
|
||||
@@ -2400,6 +2400,20 @@ class JoinTest(QueryTest, AssertsCompiledSQL):
|
||||
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()."""
|
||||
|
||||
Reference in New Issue
Block a user