Documentation should mention that signatures of empty dicts cannot be guessed.
Submitted by Barry Warsaw
Assigned to Simon McVittie
Description
This bug was reported in an Ubuntu dbus service:
https://bugs.launchpad.net/ubuntu/+source/ubuntuone-client/+bug/711162
Eventually traced to message.append(), and from there to _signature_string_from_pyobject(), which attempts to introspect the dictionary for the mapping signature. Probably rightly so (refuse the temptation to guess), an empty dictionary cannot be introspected:
if (!PyDict_Next(obj, &pos, &key, &value)) {
/* No items, so fail. Or should we guess "a{vv}"? */
PyErr_SetString(PyExc_ValueError, "Unable to guess signature "
"from an empty dict");
return NULL;
}
Here's the original bug's traceback:
https://launchpadlibrarian.net/63286991/Traceback.txt
This fix:
https://code.launchpad.net/~alecu/ubuntuone-client/signature-dict/+merge/107265
shows that substituting dbus.Dictionary({}, signature='ss') instead of {} fixes the problem, which seems reasonable. One user asks:
i mean
introspecting from the server side. ie, it already knows the expected
signature is ia{ss} or whatever for example. it could then coerce {}
to be {"", ""} or just send whatever an acceptable equivalent is to
mean empty. of course, if dbus has no way to send empy values at all,
that's another issue.
But in any case, it should probably be mentioned in the documentation that implicit signatures of empty dictionaries cannot be guessed, and dbus.Dictionary() with an explicit signature should be used instead.