From: Mike Bayer Date: Mon, 17 Mar 2014 20:25:51 +0000 (-0400) Subject: - Improved an error message which would occur if a query() were made X-Git-Tag: rel_0_9_4~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ec01ab35a6c0cfdae6ce8a5f84d5ccaf90a3c44;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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. --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index f861a3c6cc..08e44a0fdb 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -11,6 +11,16 @@ .. 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 diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 81be0e63cd..0f5b8bf88a 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1843,6 +1843,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( diff --git a/test/orm/test_joins.py b/test/orm/test_joins.py index e0eb7c3e01..e820f3fc4c 100644 --- a/test/orm/test_joins.py +++ b/test/orm/test_joins.py @@ -396,6 +396,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):