summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-08-28 12:38:04 +0100
committerMichael Williamson <mike@zwobble.org>2016-08-28 12:38:04 +0100
commit94fe6fe05dacf6f38dd0541fd59b0ca76b440c4e (patch)
treedb5c13fd44a729a2352c4ae69ac1f3c8a5abc94a
parent117997cd5b849a236208cf9ea16f0f09c6962804 (diff)
downloadsqlalchemy-pr/304.tar.gz
Provide more informative error when joining with no entitiespr/304
-rw-r--r--lib/sqlalchemy/orm/query.py9
-rw-r--r--test/orm/test_joins.py13
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index f15f4340b..592c685ca 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -2125,10 +2125,15 @@ class Query(object):
left = self._entities[0].entity_zero_or_selectable
if left is None:
+ if self._entities:
+ problem = "Don't know how to join from %s" % self._entities[0]
+ else:
+ problem = "No entities to join from"
+
raise sa_exc.InvalidRequestError(
- "Don't know how to join from %s; please use "
+ "%s; please use "
"select_from() to establish the left "
- "entity/selectable of this join" % self._entities[0])
+ "entity/selectable of this join" % problem)
if left is right and \
not create_aliases:
diff --git a/test/orm/test_joins.py b/test/orm/test_joins.py
index e14af635d..01f8627bc 100644
--- a/test/orm/test_joins.py
+++ b/test/orm/test_joins.py
@@ -447,6 +447,19 @@ class JoinTest(QueryTest, AssertsCompiledSQL):
sess.query(literal_column('x'), User).join, Address
)
+ def test_left_is_none_and_query_has_no_entities(self):
+ User = self.classes.User
+ Address = self.classes.Address
+
+ sess = create_session()
+
+ assert_raises_message(
+ sa_exc.InvalidRequestError,
+ "No entities to join from; please use select_from\(\) to "
+ "establish the left entity/selectable of this join",
+ sess.query().join, Address
+ )
+
def test_isouter_flag(self):
User = self.classes.User