rset.py
changeset 3777 3ef8cdb5fb1c
parent 3720 5376aaadd16b
parent 3766 9e5dc4b1ada4
child 3890 d7a270f50f54
--- a/rset.py	Mon Oct 19 20:22:01 2009 +0200
+++ b/rset.py	Wed Oct 21 17:32:20 2009 +0200
@@ -117,11 +117,10 @@
                          self.description +rset.description)
         return self.req.decorate_rset(rset)
 
-    def copy(self):
-        rset = ResultSet(self.rows[:], self.rql, self.args, self.description[:])
-        return self.req.decorate_rset(rset)
-
-    def _prepare_copy(self, rows, descr):
+    def copy(self, rows=None, descr=None):
+        if rows is None:
+            rows = self.rows[:]
+            descr = self.description[:]
         rset = ResultSet(rows, self.rql, self.args, descr)
         return self.req.decorate_rset(rset)
 
@@ -140,7 +139,7 @@
         :rtype: `ResultSet`
         """
         rows, descr = [], []
-        rset = self._prepare_copy(rows, descr)
+        rset = self.copy(rows, descr)
         for row, desc in zip(self.rows, self.description):
             nrow, ndesc = transformcb(row, desc)
             if ndesc: # transformcb returns None for ndesc to skip that row
@@ -163,7 +162,7 @@
         :rtype: `ResultSet`
         """
         rows, descr = [], []
-        rset = self._prepare_copy(rows, descr)
+        rset = self.copy(rows, descr)
         for i in xrange(len(self)):
             if not filtercb(self.get_entity(i, col)):
                 continue
@@ -190,7 +189,7 @@
         :rtype: `ResultSet`
         """
         rows, descr = [], []
-        rset = self._prepare_copy(rows, descr)
+        rset = self.copy(rows, descr)
         if col >= 0:
             entities = sorted(enumerate(self.entities(col)),
                               key=lambda (i, e): keyfunc(e), reverse=reverse)
@@ -237,7 +236,7 @@
 
             if key not in mapping:
                 rows, descr = [], []
-                rset = self._prepare_copy(rows, descr)
+                rset = self.copy(rows, descr)
                 mapping[key] = rset
                 result.append(rset)
             else:
@@ -332,7 +331,7 @@
                     else:
                         self.req.drop_entity_cache(entity.eid)
         else:
-            rset = self._prepare_copy(rows, descr)
+            rset = self.copy(rows, descr)
             if not offset:
                 # can copy built entity caches
                 copy_cache(rset, 'get_entity', self)
@@ -558,6 +557,9 @@
         # UNION query, find the subquery from which this entity has been found
         select = rqlst.locate_subquery(locate_query_col, etype, self.args)[0]
         col = rqlst.subquery_selection_index(select, col)
+        if col is None:
+            # XXX unexpected, should fix subquery_selection_index ?
+            return None, None
         try:
             myvar = select.selection[col].variable
         except AttributeError: