diff --git a/bson/__init__.py b/bson/__init__.py index 088ed0e990..91bb094cce 100644 --- a/bson/__init__.py +++ b/bson/__init__.py @@ -134,7 +134,7 @@ def _get_string(data, position, obj_end, opts, dummy): opts.unicode_decode_error_handler, True)[0], end + 1 -def _get_object(data, position, obj_end, opts, dummy): +def _get_object(data, position, obj_end, opts, element_name): """Decode a BSON subdocument to opts.document_class or bson.dbref.DBRef.""" obj_size = _UNPACK_INT(data[position:position + 4])[0] end = position + obj_size - 1 @@ -143,7 +143,7 @@ def _get_object(data, position, obj_end, opts, dummy): if end >= obj_end: raise InvalidBSON("invalid object length") if _raw_document_class(opts.document_class): - return (opts.document_class(data[position:end + 1], opts), + return (opts.document_class(data[position:end + 1], opts, element_name), position + obj_size) obj = _elements_to_dict(data, position + 4, end, opts) diff --git a/bson/_cbsonmodule.c b/bson/_cbsonmodule.c index 31d1f49181..716ae6aed3 100644 --- a/bson/_cbsonmodule.c +++ b/bson/_cbsonmodule.c @@ -1769,8 +1769,8 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer, if (options->is_raw_bson) { value = PyObject_CallFunction( - options->document_class, BYTES_FORMAT_STRING "O", - buffer + *position, size, options->options_obj); + options->document_class, BYTES_FORMAT_STRING "OO", + buffer + *position, size, options->options_obj, name); if (!value) { goto invalid; } diff --git a/bson/codec_options.py b/bson/codec_options.py index 7ef4151deb..ea47c5dc29 100644 --- a/bson/codec_options.py +++ b/bson/codec_options.py @@ -69,8 +69,8 @@ def __new__(cls, document_class=dict, tz_aware=False, uuid_representation=PYTHON_LEGACY, unicode_decode_error_handler="strict", tzinfo=None): - if not (issubclass(document_class, MutableMapping) or - _raw_document_class(document_class)): + if not (_raw_document_class(document_class) or + issubclass(document_class, MutableMapping)): raise TypeError("document_class must be dict, bson.son.SON, " "bson.raw_bson.RawBSONDocument, or a " "sublass of collections.MutableMapping")