From 6a44855d1b57ec430e879407ce90e09ccbe4b398 Mon Sep 17 00:00:00 2001 From: Michael Elovskikh Date: Mon, 29 May 2017 13:16:27 +0500 Subject: [PATCH 1/2] Check _RAW_BSON_DOCUMENT_MARKER at CodecOptions.document_class first --- bson/codec_options.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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") From 0401552797a7173b32c5e14596b533ae8a4e3523 Mon Sep 17 00:00:00 2001 From: Michael Elovskikh Date: Thu, 1 Jun 2017 16:21:38 +0500 Subject: [PATCH 2/2] Return element_name back to raw encoder class --- bson/__init__.py | 4 ++-- bson/_cbsonmodule.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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; }