PYTHON-4666 Fix handling of large documents in client.bulk_write (#1798)
This commit is contained in:
parent
f16206cb89
commit
ad888797cf
@ -1123,6 +1123,8 @@ def _client_batched_op_msg_impl(
|
||||
new_message_size = total_ops_length + total_ns_length + op_length + ns_length
|
||||
# We have enough data, return this batch.
|
||||
if new_message_size > max_doc_sequences_bytes:
|
||||
if idx == 0:
|
||||
_raise_document_too_large(op_type, op_length, max_bson_size + _COMMAND_OVERHEAD)
|
||||
break
|
||||
|
||||
# Add op and ns documents to this batch.
|
||||
|
||||
@ -512,17 +512,15 @@ class TestClientBulkWriteCRUD(AsyncIntegrationTest):
|
||||
# Document too large.
|
||||
b_repeated = "b" * self.max_message_size_bytes
|
||||
models = [InsertOne(namespace="db.coll", document={"a": b_repeated})]
|
||||
with self.assertRaises(InvalidOperation) as context:
|
||||
with self.assertRaises(DocumentTooLarge):
|
||||
await client.bulk_write(models=models)
|
||||
self.assertIn("cannot do an empty bulk write", context.exception._message)
|
||||
|
||||
# Namespace too large.
|
||||
c_repeated = "c" * self.max_message_size_bytes
|
||||
namespace = f"db.{c_repeated}"
|
||||
models = [InsertOne(namespace=namespace, document={"a": "b"})]
|
||||
with self.assertRaises(InvalidOperation) as context:
|
||||
with self.assertRaises(DocumentTooLarge):
|
||||
await client.bulk_write(models=models)
|
||||
self.assertIn("cannot do an empty bulk write", context.exception._message)
|
||||
|
||||
@async_client_context.require_version_min(8, 0, 0, -24)
|
||||
@unittest.skipUnless(_HAVE_PYMONGOCRYPT, "pymongocrypt is not installed")
|
||||
|
||||
@ -512,17 +512,15 @@ class TestClientBulkWriteCRUD(IntegrationTest):
|
||||
# Document too large.
|
||||
b_repeated = "b" * self.max_message_size_bytes
|
||||
models = [InsertOne(namespace="db.coll", document={"a": b_repeated})]
|
||||
with self.assertRaises(InvalidOperation) as context:
|
||||
with self.assertRaises(DocumentTooLarge):
|
||||
client.bulk_write(models=models)
|
||||
self.assertIn("cannot do an empty bulk write", context.exception._message)
|
||||
|
||||
# Namespace too large.
|
||||
c_repeated = "c" * self.max_message_size_bytes
|
||||
namespace = f"db.{c_repeated}"
|
||||
models = [InsertOne(namespace=namespace, document={"a": "b"})]
|
||||
with self.assertRaises(InvalidOperation) as context:
|
||||
with self.assertRaises(DocumentTooLarge):
|
||||
client.bulk_write(models=models)
|
||||
self.assertIn("cannot do an empty bulk write", context.exception._message)
|
||||
|
||||
@client_context.require_version_min(8, 0, 0, -24)
|
||||
@unittest.skipUnless(_HAVE_PYMONGOCRYPT, "pymongocrypt is not installed")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user