Prevent ObjectIDs from being pickled. (#42)

This commit is contained in:
Robert Nishihara
2016-10-21 15:42:29 -07:00
committed by Philipp Moritz
parent da3a3127e0
commit db6375701e
2 changed files with 26 additions and 0 deletions
+8
View File
@@ -51,9 +51,17 @@ static PyObject *PyObjectID_id(PyObject *self) {
UNIQUE_ID_SIZE);
}
static PyObject *PyObjectID___reduce__(PyObjectID *self) {
PyErr_SetString(CommonError, "ObjectID objects cannot be serialized.");
return NULL;
}
static PyMethodDef PyObjectID_methods[] = {
{"id", (PyCFunction) PyObjectID_id, METH_NOARGS,
"Return the hash associated with this ObjectID"},
{"__reduce__", (PyCFunction) PyObjectID___reduce__, METH_NOARGS,
"Say how to pickle this ObjectID. This raises an exception to prevent"
"object IDs from being serialized."},
{NULL} /* Sentinel */
};