]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Improved an error message which would occur if a query() were made
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 17 Mar 2014 20:25:51 +0000 (16:25 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 17 Mar 2014 20:26:09 +0000 (16:26 -0400)
against a non-selectable, such as a :func:`.literal_column`, and then
an attempt was made to use :meth:`.Query.join` such that the "left"
side would be determined as ``None`` and then fail.  This condition
is now detected explicitly.

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/orm/query.py
test/orm/test_joins.py

index 803cef479d65dc33325f9c450235d4b1d1026cdb..a0df6a28794d59dcc3cc506c6d0725eae0378ae8 100644 (file)
 .. changelog::
     :version: 0.8.6
 
+    .. change::
+        :tags: bug, orm
+        :versions: 0.9.4
+
+        Improved an error message which would occur if a query() were made
+        against a non-selectable, such as a :func:`.literal_column`, and then
+        an attempt was made to use :meth:`.Query.join` such that the "left"
+        side would be determined as ``None`` and then fail.  This condition
+        is now detected explicitly.
+
     .. change::
         :tags: bug, sql
         :versions: 0.9.4
index bd8152170aeda67d7aa96497a6cacc6512b7d65d..81f49980e0d7632d5e92b2de720b8de6f6808b61 100644 (file)
@@ -1827,6 +1827,12 @@ class Query(object):
             elif self._entities:
                 left = self._entities[0].entity_zero_or_selectable
 
+        if left is None:
+            raise sa_exc.InvalidRequestError(
+                            "Don't know how to join from %s; please use "
+                            "select_from() to establish the left "
+                            "entity/selectable of this join" % self._entities[0])
+
         if left is right and \
                 not create_aliases:
             raise sa_exc.InvalidRequestError(
index 2bf0d8d9293daf77eed341fd7a8dd37d4c0eabdf..f37ce7b61ea4158f322005429cf7b2f3b73060ff 100644 (file)
@@ -394,6 +394,19 @@ class JoinTest(QueryTest, AssertsCompiledSQL):
             "ON addresses.id = orders.address_id"
         )
 
+    def test_left_is_none(self):
+        User = self.classes.User
+        Address = self.classes.Address
+
+        sess = create_session()
+
+        assert_raises_message(
+            sa_exc.InvalidRequestError,
+            "Don't know how to join from x; please use select_from() to "
+            "establish the left entity/selectable of this join",
+            sess.query(literal_column('x'), User).join, Address
+        )
+
     def test_join_on_synonym(self):
 
         class User(object):