Skip to content

Commit b9f4f79

Browse files
NoahStappblink1073
andauthored
Revert "PYTHON-4915 - Add guidance on adding _id fields to documents to CRUD spec, reorder client.bulk_write generated _id fields" (#2055)
Co-authored-by: Steven Silvester <steve.silvester@mongodb.com>
1 parent 493fc2a commit b9f4f79

File tree

4 files changed

+1
-134
lines changed

4 files changed

+1
-134
lines changed

pymongo/message.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import datetime
2525
import random
2626
import struct
27-
from collections import ChainMap
2827
from io import BytesIO as _BytesIO
2928
from typing import (
3029
TYPE_CHECKING,
@@ -1116,18 +1115,8 @@ def _check_doc_size_limits(
11161115
# key and the index of its namespace within ns_info as its value.
11171116
op_doc[op_type] = ns_info[namespace] # type: ignore[index]
11181117

1119-
# Since the data document itself is nested within the insert document
1120-
# it won't be automatically re-ordered by the BSON conversion.
1121-
# We use ChainMap here to make the _id field the first field instead.
1122-
doc_to_encode = op_doc
1123-
if real_op_type == "insert":
1124-
doc = op_doc["document"]
1125-
if not isinstance(doc, RawBSONDocument):
1126-
doc_to_encode = op_doc.copy() # type: ignore[attr-defined] # Shallow copy
1127-
doc_to_encode["document"] = ChainMap(doc, {"_id": doc["_id"]}) # type: ignore[index]
1128-
11291118
# Encode current operation doc and, if newly added, namespace doc.
1130-
op_doc_encoded = _dict_to_bson(doc_to_encode, False, opts)
1119+
op_doc_encoded = _dict_to_bson(op_doc, False, opts)
11311120
op_length = len(op_doc_encoded)
11321121
if ns_doc:
11331122
ns_doc_encoded = _dict_to_bson(ns_doc, False, opts)

test/asynchronous/test_client_bulk_write.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
import os
1919
import sys
2020

21-
from bson import encode
22-
from bson.raw_bson import RawBSONDocument
23-
2421
sys.path[0:0] = [""]
2522

2623
from test.asynchronous import (
@@ -87,17 +84,6 @@ async def test_formats_write_error_correctly(self):
8784
self.assertEqual(write_error["idx"], 1)
8885
self.assertEqual(write_error["op"], {"insert": 0, "document": {"_id": 1}})
8986

90-
@async_client_context.require_version_min(8, 0, 0, -24)
91-
@async_client_context.require_no_serverless
92-
async def test_raw_bson_not_inflated(self):
93-
doc = RawBSONDocument(encode({"a": "b" * 100}))
94-
models = [
95-
InsertOne(namespace="db.coll", document=doc),
96-
]
97-
await self.client.bulk_write(models=models)
98-
99-
self.assertIsNone(doc._RawBSONDocument__inflated_doc)
100-
10187

10288
# https://github.com/mongodb/specifications/tree/master/source/crud/tests
10389
class TestClientBulkWriteCRUD(AsyncIntegrationTest):

test/mockupdb/test_id_ordering.py

Lines changed: 0 additions & 94 deletions
This file was deleted.

test/test_client_bulk_write.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
import os
1919
import sys
2020

21-
from bson import encode
22-
from bson.raw_bson import RawBSONDocument
23-
2421
sys.path[0:0] = [""]
2522

2623
from test import (
@@ -87,17 +84,6 @@ def test_formats_write_error_correctly(self):
8784
self.assertEqual(write_error["idx"], 1)
8885
self.assertEqual(write_error["op"], {"insert": 0, "document": {"_id": 1}})
8986

90-
@client_context.require_version_min(8, 0, 0, -24)
91-
@client_context.require_no_serverless
92-
def test_raw_bson_not_inflated(self):
93-
doc = RawBSONDocument(encode({"a": "b" * 100}))
94-
models = [
95-
InsertOne(namespace="db.coll", document=doc),
96-
]
97-
self.client.bulk_write(models=models)
98-
99-
self.assertIsNone(doc._RawBSONDocument__inflated_doc)
100-
10187

10288
# https://github.com/mongodb/specifications/tree/master/source/crud/tests
10389
class TestClientBulkWriteCRUD(IntegrationTest):

0 commit comments

Comments
 (0)