summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2009-01-06 04:30:11 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2009-01-06 04:30:11 +0000
commitd14317fd7a05be0ec4586981e8875ae563558f81 (patch)
tree5574a7bf1bf37c16bb98313a977c850afd00d3ff /lib/sqlalchemy
parente1401bd28e5d127ef1c079b5426be37d63ab0157 (diff)
downloadsqlalchemy-d14317fd7a05be0ec4586981e8875ae563558f81.tar.gz
- query.join() raises an error when the target of the join
doesn't match the property-based attribute - while it's unlikely anyone is doing this, the SQLAlchemy author was guilty of this particular loosey-goosey behavior.
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/query.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 7a5721761..c5349e052 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -784,11 +784,10 @@ class Query(object):
right_entity = None
for arg1 in util.to_list(keys):
- prop = None
aliased_entity = False
alias_criterion = False
left_entity = right_entity
- right_entity = right_mapper = None
+ prop = of_type = right_entity = right_mapper = None
if isinstance(arg1, tuple):
arg1, arg2 = arg1
@@ -827,6 +826,7 @@ class Query(object):
descriptor, prop = _entity_descriptor(left_entity, onclause)
right_mapper = prop.mapper
+
if not right_entity:
right_entity = right_mapper
elif onclause is None:
@@ -849,7 +849,12 @@ class Query(object):
raise sa_exc.InvalidRequestError("Could not find a FROM clause to join from")
mp, right_selectable, is_aliased_class = _entity_info(right_entity)
-
+
+ if mp is not None and right_mapper is not None and not mp.common_parent(right_mapper):
+ raise sa_exc.InvalidRequestError(
+ "Join target %s does not correspond to the right side of join condition %s" % (right_entity, onclause)
+ )
+
if not right_mapper and mp:
right_mapper = mp
@@ -886,8 +891,10 @@ class Query(object):
if prop.secondary:
self.__currenttables.add(prop.secondary)
self.__currenttables.add(prop.table)
-
- if not right_entity:
+
+ if of_type:
+ right_entity = of_type
+ else:
right_entity = prop.mapper
if alias_criterion: