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

index cf32668862eb08a04608f613a42a0a50c03ed89d..7eb625cdeaf87b804daf2994be34acdb678fbe19 100644 (file)
@@ -274,12 +274,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 474f3da42b250bfd833fcb3b03cecd86700e092e..9ec0cd2bca490cfe343cebb28b2425a69381e202 100755 (executable)
@@ -127,6 +127,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([], self.f.items(), "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([], self.f.items(), "expected empty db after test")
+
     def test_set_location(self):
         self.assertEqual(self.f.set_location('e'), ('e', self.d['e']))