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: Cursors not correctly closed after exception.
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, ragnar
Priority: normal Keywords:

Created on 2005-05-28 12:48 by ragnar, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg25438 - (view) Author: Ragnar Ouchterlony (ragnar) Date: 2005-05-28 12:48
If an exception occurs when going through a database,
the cursors will not be correctly reset.

If I manually set the cursor to None (by doing db.dbc =
None) it will work fine.

>>> db = bsddb.btopen('/tmp/test.db', 'c')
>>> db.first()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/bsddb/__init__.py", line
264, in first
    rv = self.dbc.first()
_bsddb.DBNotFoundError: (-30990, 'DB_NOTFOUND: No
matching key/data pair found')
>>> db['foo'] = 'bar'
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/bsddb/__init__.py", line
217, in __setitem__
    self._closeCursors()
  File "/usr/lib/python2.4/bsddb/__init__.py", line
192, in _closeCursors
    self.saved_dbc_key = c.current(0,0,0)[0]
bsddb._db.DBInvalidArgError: (22, 'Invalid argument --
Cursor position must be set before performing this
operation')

Here, I first open a new database. Since it is empty,
db.first() will fail. When I after that try to add a
key/value pair to the database it fails, since it tries
to close an invalid cursor.

>>> db = bsddb.btopen('/tmp/test.db', 'c')
>>> db.first()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/bsddb/__init__.py", line
264, in first
    rv = self.dbc.first()
_bsddb.DBNotFoundError: (-30990, 'DB_NOTFOUND: No
matching key/data pair found')
>>> db.dbc = None
>>> db['foo'] = 'bar'
>>> db
{'foo': 'bar'}

Here I do "db.dbc = None" after the exception and now
it works just fine.
msg25439 - (view) Author: Ragnar Ouchterlony (ragnar) Date: 2005-05-30 07:59
Logged In: YES 
user_id=1394

The bugreport refers to bsddb. I did not make that entirely
clear.
msg25440 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-20 20:30
Logged In: YES 
user_id=849994

Fixed in rev. 42525, 42526.
History
Date User Action Args
2022-04-11 14:56:11adminsetgithub: 42027
2005-05-28 12:48:42ragnarcreate