--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 4773
+
+ Fixed regression caused by :ticket:`4365` where a join from an entity to
+ itself without using aliases no longer raises an informative error message,
+ instead failing on an assertion. The informative error condition has been
+ restored.
+
use_entity_index,
) = self._join_place_explicit_left_side(left)
- # this should never happen because we would not have found a place
- # to join on
- assert left is not right or create_aliases
+ if left is right and not create_aliases:
+ raise sa_exc.InvalidRequestError(
+ "Can't construct a join from %s to %s, they "
+ "are the same entity" % (left, right)
+ )
# the right side as given often needs to be adapted. additionally
# a lot of things can be wrong with it. handle all that and
)
self.assert_compile(
- join(User, oalias2, User.id == oalias2.user_id,
- isouter=True, full=True),
+ join(
+ User,
+ oalias2,
+ User.id == oalias2.user_id,
+ isouter=True,
+ full=True,
+ ),
"users FULL OUTER JOIN orders AS orders_1 "
"ON users.id = orders_1.user_id",
use_default_dialect=True,
use_default_dialect=True,
)
+ def test_join_to_self_no_aliases_raises(self):
+ Node = self.classes.Node
+
+ s = Session()
+ assert_raises_message(
+ sa.exc.InvalidRequestError,
+ "Can't construct a join from mapped class Node->nodes to mapped "
+ "class Node->nodes, they are the same entity",
+ s.query(Node).join,
+ Node.children,
+ )
+
def test_explicit_join_1(self):
Node = self.classes.Node
n1 = aliased(Node)