Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
python: Clear AttributeError sometimes created in callback_defined (R…
…HBZ#1693283).

When we test if a callback is defined in the Python code, we try to
convert the callback name into a Python attribute using
PyObject_GetAttrString.  If this fails (indicating the callback isn't
defined) it sets the global PyErr indicator to some random error
message.

At a later point we may test the global PyErr and report this error
unexpectedly, which is what happened in
https://bugzilla.redhat.com/show_bug.cgi?id=1693283#c7

A simple way to fix this is to call PyErr_Clear() along the not found
path.

Thanks: Tomáš Golembiovský and Junqin Zhou.
  • Loading branch information
rwmjones committed Mar 27, 2019
1 parent 05b59ef commit 466b92b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plugins/python/python.c
Expand Up @@ -92,8 +92,10 @@ callback_defined (const char *name, PyObject **obj_rtn)
assert (module != NULL);

obj = PyObject_GetAttrString (module, name);
if (!obj)
if (!obj) {
PyErr_Clear (); /* Clear the AttributeError from testing attr. */
return 0;
}
if (!PyCallable_Check (obj)) {
nbdkit_debug ("object %s isn't callable", name);
Py_DECREF (obj);
Expand Down

0 comments on commit 466b92b

Please sign in to comment.