[pybsddb] _db_associateCallback Error Handling
Craig Northway
craig.northway at gmail.com
Wed Apr 8 07:39:38 CEST 2009
Hi,
I do not think that errors are correctly handled in
_db_associateCallback when a callback fails.
If a callback returns a value that doesn't fit the required formats
(int, bytes, list, etc...) control falls through to an else statement
and an exception is raised.
else {
PyErr_SetString(
PyExc_TypeError,
#if (PY_VERSION_HEX < 0x03000000)
"DB associate callback should return DB_DONOTINDEX/string/list of strings.");
#else
"DB associate callback should return DB_DONOTINDEX/bytes/list of bytes.");
#endif
PyErr_Print();
}
However in the case that the callback throws an exception (say there
is a bug in the callback) and returns NULL, the exception is printed,
control will fall through to the end of the function and DB_DONOTINDEX
is returned:
if (args == NULL || result == NULL) {
PyErr_Print();
}
Thus the operation of the python program making use of the secondary
indexed database will continue.
I think the case where the exception occurs in the callback should
result in an exception being raised by the python bindings the same as
the callback returning an incorrect format.
If you agree this is a pretty similar change, adding a PyErr_SetString
to the result == NULL case should do the trick.
Thanks,
Craig
More information about the pybsddb
mailing list