Commits

Mike Bayer  committed 0359f44

- another fix to subquery correlation so that a subquery which has only one FROM
element will *not* correlate that single element, since at least one FROM element is
required in a query.

  • Participants
  • Parent commits 4c1ed46

Comments (0)

Files changed (3)

   is constructed with individual calls to append_column(); this fixes an ORM
   bug whereby nested select statements were not getting correlated with the 
   main select generated by the Query object.
+  - another fix to subquery correlation so that a subquery which has only one FROM
+  element will *not* correlate that single element, since at least one FROM element is 
+  required in a query.
   - default "timezone" setting is now False.  this corresponds to Python's datetime
   behavior as well as Postgres' timestamp/time types (which is the only timezone-sensitive
   dialect at the moment) [ticket:414]

File lib/sqlalchemy/sql.py

         else:
             return None
 
-    froms = property(lambda self: self.__froms.difference(self.__hide_froms).difference(self.__correlated), doc="""a collection containing all elements of the FROM clause""")
+    def _calc_froms(self):
+        f = self.__froms.difference(self.__hide_froms)
+        if (len(f) > 1):
+            return f.difference(self.__correlated)
+        else:
+            return f
+    froms = property(_calc_froms, doc="""a collection containing all elements of the FROM clause""")
 
     def accept_visitor(self, visitor):
         for f in self.froms:

File test/sql/select.py

 (SELECT sq.mytable_myid AS sq_mytable_myid, sq.mytable_name AS sq_mytable_name, \
 sq.mytable_description AS sq_mytable_description, sq.myothertable_otherid AS sq_myothertable_otherid, \
 sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") AS sq) AS sq2")
-
+    
+    def testdontovercorrelate(self):
+        self.runtest(select([table1], from_obj=[table1, table1.select()]), """SELECT mytable.myid, mytable.name, mytable.description FROM mytable, (SELECT mytable.myid AS myid, mytable.name AS name, mytable.description AS description FROM mytable)""")
+        
     def testwheresubquery(self):
         # TODO: this tests that you dont get a "SELECT column" without a FROM but its not working yet.
         #self.runtest(