diff --git a/bson/_cbsonmodule.c b/bson/_cbsonmodule.c index e606809ba..ed0179fa1 100644 --- a/bson/_cbsonmodule.c +++ b/bson/_cbsonmodule.c @@ -1485,6 +1485,9 @@ int write_dict(PyObject* self, buffer_t buffer, Py_DECREF(value); } Py_DECREF(iter); + if (PyErr_Occurred()) { + return 0; + } /* write null byte and fill in length */ if (!buffer_write_bytes(buffer, &zero, 1)) {