Skip to content

Commit

Permalink
try an additional reload before giving up on SON
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Dirolf committed Apr 1, 2010
1 parent 1a051df commit 946bedc
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions pymongo/_cbsonmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,12 +841,21 @@ static int write_dict(bson_buffer* buffer, PyObject* dict, unsigned char check_k
}
}
} else {
PyObject* errmsg = PyString_FromString("encoder expected a mapping type but got: ");
PyObject* repr = PyObject_Repr(dict);
PyString_ConcatAndDel(&errmsg, repr);
PyErr_SetString(PyExc_TypeError, PyString_AsString(errmsg));
Py_DECREF(errmsg);
return 0;
/* Try a reload! */
_reload_python_objects();
if (PyObject_IsInstance(dict, SON)) {
if (!write_son(buffer, dict, start_position, length_location, check_keys, top_level)) {
return 0;
}
}
else {
PyObject* errmsg = PyString_FromString("encoder expected a mapping type but got: ");
PyObject* repr = PyObject_Repr(dict);
PyString_ConcatAndDel(&errmsg, repr);
PyErr_SetString(PyExc_TypeError, PyString_AsString(errmsg));
Py_DECREF(errmsg);
return 0;
}
}

/* write null byte and fill in length */
Expand Down

0 comments on commit 946bedc

Please sign in to comment.