Skip to content

Commit

Permalink
Revert "PYTHON-4915 - Add guidance on adding _id fields to documents …
Browse files Browse the repository at this point in the history
…to CRUD …"

This reverts commit 72a5109.
  • Loading branch information
blink1073 authored Jan 10, 2025
1 parent 493fc2a commit 1c62396
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 134 deletions.
13 changes: 1 addition & 12 deletions pymongo/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import datetime
import random
import struct
from collections import ChainMap
from io import BytesIO as _BytesIO
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -1116,18 +1115,8 @@ def _check_doc_size_limits(
# key and the index of its namespace within ns_info as its value.
op_doc[op_type] = ns_info[namespace] # type: ignore[index]

# Since the data document itself is nested within the insert document
# it won't be automatically re-ordered by the BSON conversion.
# We use ChainMap here to make the _id field the first field instead.
doc_to_encode = op_doc
if real_op_type == "insert":
doc = op_doc["document"]
if not isinstance(doc, RawBSONDocument):
doc_to_encode = op_doc.copy() # type: ignore[attr-defined] # Shallow copy
doc_to_encode["document"] = ChainMap(doc, {"_id": doc["_id"]}) # type: ignore[index]

# Encode current operation doc and, if newly added, namespace doc.
op_doc_encoded = _dict_to_bson(doc_to_encode, False, opts)
op_doc_encoded = _dict_to_bson(op_doc, False, opts)
op_length = len(op_doc_encoded)
if ns_doc:
ns_doc_encoded = _dict_to_bson(ns_doc, False, opts)
Expand Down
14 changes: 0 additions & 14 deletions test/asynchronous/test_client_bulk_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import os
import sys

from bson import encode
from bson.raw_bson import RawBSONDocument

sys.path[0:0] = [""]

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

@async_client_context.require_version_min(8, 0, 0, -24)
@async_client_context.require_no_serverless
async def test_raw_bson_not_inflated(self):
doc = RawBSONDocument(encode({"a": "b" * 100}))
models = [
InsertOne(namespace="db.coll", document=doc),
]
await self.client.bulk_write(models=models)

self.assertIsNone(doc._RawBSONDocument__inflated_doc)


# https://github.com/mongodb/specifications/tree/master/source/crud/tests
class TestClientBulkWriteCRUD(AsyncIntegrationTest):
Expand Down
94 changes: 0 additions & 94 deletions test/mockupdb/test_id_ordering.py

This file was deleted.

14 changes: 0 additions & 14 deletions test/test_client_bulk_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import os
import sys

from bson import encode
from bson.raw_bson import RawBSONDocument

sys.path[0:0] = [""]

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

@client_context.require_version_min(8, 0, 0, -24)
@client_context.require_no_serverless
def test_raw_bson_not_inflated(self):
doc = RawBSONDocument(encode({"a": "b" * 100}))
models = [
InsertOne(namespace="db.coll", document=doc),
]
self.client.bulk_write(models=models)

self.assertIsNone(doc._RawBSONDocument__inflated_doc)


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

0 comments on commit 1c62396

Please sign in to comment.