]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where Query would crash if a join() with no clear
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 4 Nov 2009 13:28:28 +0000 (13:28 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 4 Nov 2009 13:28:28 +0000 (13:28 +0000)
"left" side were called when a non-mapped column entity
appeared in the columns list. [ticket:1602]

CHANGES
lib/sqlalchemy/orm/query.py
test/orm/test_query.py

diff --git a/CHANGES b/CHANGES
index 1fda8a31d37270c73d5c64b568048ede2d209404..09375c42db4bb2eb28643c5cc417bb0ff73771e7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -32,6 +32,10 @@ CHANGES
     
     - Fixed the call to get_committed_value() on CompositeProperty.
       [ticket:1504]
+    
+    - Fixed bug where Query would crash if a join() with no clear
+      "left" side were called when a non-mapped column entity
+      appeared in the columns list. [ticket:1602]
       
 - sql
     - Fixed the "numeric" paramstyle, which apparently is the
index 239f455622b424167ca8369825563f8d69c9707b..a3c78940b49dbe5809f3b6290a81cfce9ff3d0c4 100644 (file)
@@ -2138,10 +2138,13 @@ class _ColumnEntity(_QueryEntity):
         self.froms.add(from_obj)
 
     def corresponds_to(self, entity):
-        if _is_aliased_class(entity):
+        if self.entity_zero is None:
+            return False
+        elif _is_aliased_class(entity):
             return entity is self.entity_zero
         else:
-            return not _is_aliased_class(self.entity_zero) and entity.base_mapper.common_parent(self.entity_zero)
+            return not _is_aliased_class(self.entity_zero) and \
+                entity.base_mapper.common_parent(self.entity_zero)
             
     def _resolve_expr_against_query_aliases(self, query, expr, context):
         return query._adapt_clause(expr, False, True)
index 1934a1330f34b728e335ae4ef37a46b7e9f19b5c..c7dce9332e0b2d8e6ed1a67b8f9f9aacf5b44ffa 100644 (file)
@@ -1148,6 +1148,17 @@ class JoinTest(QueryTest):
             []
         )
     
+    def test_join_nonmapped_column(self):
+        """test that the search for a 'left' doesn't trip on non-mapped cols"""
+        sess = create_session()
+        
+        # intentionally join() with a non-existent "left" side
+        q = sess.query(User.id, literal_column('foo')).join(Order.user)
+        eq_(
+            str(q.statement.apply_labels().compile(dialect=default.DefaultDialect())),
+            "SELECT users.id AS users_id, foo \nFROM orders JOIN users ON users.id = orders.user_id"
+        ) 
+        
     def test_backwards_join(self):
         # a more controversial feature.  join from
         # User->Address, but the onclause is Address.user.