diff -r c3cec0f77eff Objects/odictobject.c --- a/Objects/odictobject.c Tue Oct 20 18:22:36 2015 +0300 +++ b/Objects/odictobject.c Thu Oct 22 11:59:17 2015 +0300 @@ -1716,7 +1716,12 @@ PyODict_SetItem(PyObject *od, PyObject * int res = PyDict_SetItem(od, key, value); if (res == 0) { res = _odict_add_new_node((PyODictObject *)od, key); - /* XXX Revert setting the value on the dict? */ + if (res < 0) { + PyObject *exc, *val, *tb; + PyErr_Fetch(&exc, &val, &tb); + (void) PyDict_DelItem(od, key); + _PyErr_ChainExceptions(exc, val, tb); + } } return res; };