]> 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:27:59 +0000 (13:27 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 4 Nov 2009 13:27:59 +0000 (13:27 +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 cc56b3a18b2cdea53d275684bf3755f877b4ceff..9e6d45a0af3ddb981d0f57b3d1589418809e6078 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -675,6 +675,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 0463c548ae51620a3d477ccfbd2fe5db4244595d..03da9956899afaacfaa4a32d54e12eb76cb1bbcb 100644 (file)
@@ -2129,10 +2129,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 79dd2a58a16325937c4b1212a8122885d9163a8e..98e85fa4110240197e88bc0efb6219a3ccc27f73 100644 (file)
@@ -1375,9 +1375,6 @@ class InheritedJoinTest(_base.MappedTest, AssertsCompiledSQL):
         
 class JoinTest(QueryTest, AssertsCompiledSQL):
     
-    def test_foo(self):
-        sess = create_session()
-    
     def test_single_name(self):
         sess = create_session()
 
@@ -1553,6 +1550,19 @@ class JoinTest(QueryTest, AssertsCompiledSQL):
             []
         )
     
+    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
+        self.assert_compile(
+            sess.query(User.id, literal_column('foo')).join(Order.user),
+            "SELECT users.id AS users_id, foo FROM orders JOIN users ON users.id = orders.user_id"
+            , use_default_dialect=True
+        )
+        
+        
+        
     def test_backwards_join(self):
         # a more controversial feature.  join from
         # User->Address, but the onclause is Address.user.