Преглед изворни кода

[datastructures] Fix LimitedSet.discard()

This was raising ValueError every time it was called, because the
argument order was backward, resulting in unbounded memory growth for
callers using discard() to remove items from LimitedSet.

Closes #3087
Dave Smith пре 10 година
родитељ
комит
214e142e91
2 измењених фајлова са 3 додато и 1 уклоњено
  1. 1 1
      celery/datastructures.py
  2. 2 0
      celery/tests/utils/test_datastructures.py

+ 1 - 1
celery/datastructures.py

@@ -602,7 +602,7 @@ class LimitedSet(object):
         except KeyError:
         except KeyError:
             return
             return
         try:
         try:
-            self._heap.remove((value, itime))
+            self._heap.remove((itime, value))
         except ValueError:
         except ValueError:
             pass
             pass
         self._data.pop(value, None)
         self._data.pop(value, None)

+ 2 - 0
celery/tests/utils/test_datastructures.py

@@ -255,6 +255,8 @@ class test_LimitedSet(Case):
         s.add('foo')
         s.add('foo')
         s.discard('foo')
         s.discard('foo')
         self.assertNotIn('foo', s)
         self.assertNotIn('foo', s)
+        self.assertEqual(len(s._data), 0)
+        self.assertEqual(len(s._heap), 0)
         s.discard('foo')
         s.discard('foo')
 
 
     def test_clear(self):
     def test_clear(self):