[Checkins] SVN: Products.ZCatalog/trunk/ Fixed addition of two LazyCat's if any of them was already flattened.

Hanno Schlichting hannosch at hannosch.eu
Wed May 18 09:01:23 EDT 2011


Log message for revision 121708:
  Fixed addition of two LazyCat's if any of them was already flattened.
  

Changed:
  U   Products.ZCatalog/trunk/CHANGES.txt
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_lazy.py

-=-
Modified: Products.ZCatalog/trunk/CHANGES.txt
===================================================================
--- Products.ZCatalog/trunk/CHANGES.txt	2011-05-18 12:15:03 UTC (rev 121707)
+++ Products.ZCatalog/trunk/CHANGES.txt	2011-05-18 13:01:23 UTC (rev 121708)
@@ -4,6 +4,8 @@
 2.13.14 (unreleased)
 --------------------
 
+- Fixed addition of two LazyCat's if any of them was already flattened.
+
 - Extend BooleanIndex by making the indexed value variable instead of
   hardcoding it to `True`. The indexed value will determine the smaller set
   automatically and choose its best value. An inline switch is done once the

Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py	2011-05-18 12:15:03 UTC (rev 121707)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py	2011-05-18 13:01:23 UTC (rev 121708)
@@ -84,7 +84,10 @@
                 if isinstance(s, LazyCat):
                     # If one of the sequences passed is itself a LazyCat, add
                     # its base sequences rather than nest LazyCats
-                    flattened_seq.extend(s._seq)
+                    if getattr(s, '_seq', None) is None:
+                        flattened_seq.extend([s._data])
+                    else:
+                        flattened_seq.extend(s._seq)
                     flattened_count += s.actual_result_count
                 elif isinstance(s, Lazy):
                     flattened_seq.append(s)

Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_lazy.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_lazy.py	2011-05-18 12:15:03 UTC (rev 121707)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_lazy.py	2011-05-18 13:01:23 UTC (rev 121708)
@@ -66,6 +66,17 @@
         self._compare(lcat, range(20))
         self.assertEqual(lcat.actual_result_count, 20)
 
+    def test_add_after_getitem(self):
+        seq1 = range(10)
+        seq2 = range(10, 20)
+        lcat1 = self._createLSeq(seq1)
+        lcat2 = self._createLSeq(seq2)
+        # turning lcat1 into a list will flatten it into _data and remove _seq
+        list(lcat1)
+        lcat = lcat1 + lcat2
+        self._compare(lcat, range(20))
+        self.assertEqual(lcat.actual_result_count, 20)
+
     def test_init_multiple(self):
         from string import hexdigits, letters
         seq1 = range(10)



More information about the checkins mailing list