PYTHON-4084 Fix BSON inflation for DBRef (#1458)
This commit is contained in:
parent
568a3b1294
commit
9d32a09e30
@ -1884,6 +1884,11 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer,
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
if (options->is_raw_bson) {
|
||||
*position += size;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Hook for DBRefs */
|
||||
value = _dbref_hook(self, value);
|
||||
if (!value) {
|
||||
|
||||
@ -22,7 +22,7 @@ sys.path[0:0] = [""]
|
||||
from test import client_context, unittest
|
||||
from test.test_client import IntegrationTest
|
||||
|
||||
from bson import Code, decode, encode
|
||||
from bson import Code, DBRef, decode, encode
|
||||
from bson.binary import JAVA_LEGACY, Binary, UuidRepresentation
|
||||
from bson.codec_options import CodecOptions
|
||||
from bson.errors import InvalidBSON
|
||||
@ -205,6 +205,14 @@ class TestRawBSONDocument(IntegrationTest):
|
||||
self.assertEqual(decode(encode(doc)), {"value": Code("x=1", {})})
|
||||
self.assertEqual(doc["value"].scope, RawBSONDocument(encode({})))
|
||||
|
||||
def test_contains_dbref(self):
|
||||
doc = RawBSONDocument(encode({"value": DBRef("test", "id")}))
|
||||
raw = {"$ref": "test", "$id": "id"}
|
||||
raw_encoded = encode(decode(encode(raw)))
|
||||
|
||||
self.assertEqual(decode(encode(doc)), {"value": DBRef("test", "id")})
|
||||
self.assertEqual(doc["value"].raw, raw_encoded)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user