]> granicus.if.org Git - python/commitdiff
reapply of r57378 to fix bug 1725856
authorGregory P. Smith <greg@mad-scientist.com>
Fri, 24 Aug 2007 05:32:10 +0000 (05:32 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Fri, 24 Aug 2007 05:32:10 +0000 (05:32 +0000)
Lib/bsddb/__init__.py
Lib/test/test_bsddb.py

index df50bce5a3b719f304b3b0e0c44c1af94c825e30..26e41b1358e8221056c773b113755630d5700341 100644 (file)
@@ -266,12 +266,16 @@ class _DBWithCursor(_iter_mixin):
 
     def first(self):
         self._checkOpen()
+        # fix 1725856: don't needlessly try to restore our cursor position
+        self.saved_dbc_key = None
         self._checkCursor()
         rv = _DeadlockWrap(self.dbc.first)
         return rv
 
     def last(self):
         self._checkOpen()
+        # fix 1725856: don't needlessly try to restore our cursor position
+        self.saved_dbc_key = None
         self._checkCursor()
         rv = _DeadlockWrap(self.dbc.last)
         return rv
index 2da404538d96b365ab9eef27f82b81b4be8da88b..dfee3dcb11436e1d3b94fca782b9c2bd6180093d 100755 (executable)
@@ -131,6 +131,22 @@ class TestBSDDB(unittest.TestCase):
             items.append(self.f.previous())
         self.assertSetEquals(items, self.d.items())
 
+    def test_first_while_deleting(self):
+        # Test for bug 1725856
+        self.assert_(len(self.d) >= 2, "test requires >=2 items")
+        for _ in self.d:
+            key = self.f.first()[0]
+            del self.f[key]
+        self.assertEqual(0, len(self.f), "expected empty db after test")
+
+    def test_last_while_deleting(self):
+        # Test for bug 1725856's evil twin
+        self.assert_(len(self.d) >= 2, "test requires >=2 items")
+        for _ in self.d:
+            key = self.f.last()[0]
+            del self.f[key]
+        self.assertEqual(0, len(self.f), "expected empty db after test")
+
     def test_set_location(self):
         self.assertEqual(self.f.set_location('e'), ('e', self.d['e']))