This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: bsddb.btopen . del of record doesn't update index
Type: Stage:
Components: Extension Modules Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: ggenellina, gregory.p.smith, quixo
Priority: normal Keywords:

Created on 2007-05-25 21:25 by quixo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
testbtopen.py quixo, 2007-05-25 21:25
Messages (5)
msg32122 - (view) Author: Charles Hixson (quixo) Date: 2007-05-25 21:25
A ram -resident database is creaed with btopen

10 records are added, keyed by sequence, value is sequence + 1 (both converted to strings).

I check to ensure that all of the records have been added.

I delete the first record, check the keys again, and it still works.

I delete the first record, check the keys again, and it fails, thusly:

python testbtopen.py
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
0
1
2
3
4
5
6
7
8
9
0 1
['1', '2', '3', '4', '5', '6', '7', '8', '9']
1
2
3
4
5
6
7
8
9
Traceback (most recent call last):
  File "testbtopen.py", line 13, in ?
    i   =       db.first()[0]
  File "/usr/lib/python2.4/site-packages/PIL/__init__.py", line 269, in first

  File "/usr/lib/python2.4/site-packages/PIL/__init__.py", line 183, in _checkCursor

_bsddb.DBNotFoundError: (-30989, 'DB_NOTFOUND: No matching key/data pair found')
charles@mandala1:~/projects/Python/bsddb$ python testbtopen.py
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
0
1
2
3
4
5
6
7
8
9
0 1
['1', '2', '3', '4', '5', '6', '7', '8', '9']
1
2
3
4
5
6
7
8
9
Traceback (most recent call last):
  File "testbtopen.py", line 13, in ?
    i   =       db.first()[0]
  File "/usr/lib/python2.4/site-packages/PIL/__init__.py", line 269, in first

  File "/usr/lib/python2.4/site-packages/PIL/__init__.py", line 183, in _checkCursor

_bsddb.DBNotFoundError: (-30989, 'DB_NOTFOUND: No matching key/data pair found')
msg32123 - (view) Author: Gabriel Genellina (ggenellina) Date: 2007-05-27 11:17
FWIW, the same thing happens on 2.5.1 on Windows. With the funny stack trace too (PIL is not remotely related, PIL/__init__.py being almost empty).
msg55240 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2007-08-24 04:26
This code deletes the item that the internal database cursor created by
the db.first() call is pointing at.  Then when db.first() is called
again it tries to reuse the same cursor.  Now to decide if thats the
expected behavior or a real problem and how to fix it...

side note: I don't know why your backtraces contained the wrong strings.
 All of mine look fine here.

also: for a simpler test case to debug, change the 10 to 2 in the
testbtopen.py file.
msg55242 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2007-08-24 04:51
My first description wasn't quite accurate.  What was happening is that
the __delitem__(i) call by del was closing the existing cursor and
saving the key it was pointing to and the first() and last() methods
were creating a new cursor and trying to restore the new cursor to the
last known position saved when __delitem__ closed the previous cursor. 
This failed as that item no longer existed.  first() and last() by their
very nature don't need to restore the cursor position since they set it
to an absolute position.  Here's the patch to fix this:

--- Lib/bsddb/__init__.py       (revision 57289)
+++ Lib/bsddb/__init__.py       (working copy)
@@ -274,12 +274,16 @@
 
     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
msg55243 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2007-08-24 05:33
Committed to HEAD as r57378
Committed to release25-maint as r57379
Committed to py3k as r57380
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 44995
2007-08-24 05:33:05gregory.p.smithsetstatus: pending -> closed
resolution: fixed
messages: + msg55243
2007-08-24 04:51:46gregory.p.smithsetstatus: open -> pending
messages: + msg55242
2007-08-24 04:26:54gregory.p.smithsetnosy: + gregory.p.smith
messages: + msg55240
2007-08-24 04:11:21gregory.p.smithsetassignee: gregory.p.smith
2007-05-25 21:25:30quixocreate