client.bulk_write has a bug in its handling of large documents:
>>> res = client.bulk_write([InsertOne({'a':'a'*((47*1024*1024)-10)}, "test.test")])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/shane/git/mongo-python-driver/pymongo/_csot.py", line 120, in csot_wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/mongo_client.py", line 2342, in bulk_write
return blk.execute(session, _Op.BULK_WRITE)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/client_bulk.py", line 782, in execute
result = self.execute_command(session, operation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/client_bulk.py", line 650, in execute_command
self.client._retryable_write(
File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/mongo_client.py", line 1872, in _retryable_write
return self._retry_with_session(retryable, func, s, bulk, operation, operation_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/mongo_client.py", line 1758, in _retry_with_session
return self._retry_internal(
^^^^^^^^^^^^^^^^^^^^^
File "/Users/shane/git/mongo-python-driver/pymongo/_csot.py", line 120, in csot_wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/mongo_client.py", line 1804, in _retry_internal
).run()
^^^^^
File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/mongo_client.py", line 2521, in run
return self._read() if self._is_read else self._write()
^^^^^^^^^^^^^
File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/mongo_client.py", line 2643, in _write
return self._func(self._session, conn, self._retryable) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/client_bulk.py", line 641, in retryable_bulk
self._execute_command(
File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/client_bulk.py", line 544, in _execute_command
raw_result, to_send_ops, _ = self._execute_batch(bwc, cmd, ops) # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/client_bulk.py", line 423, in _execute_batch
request_id, msg, to_send_ops, to_send_ns = bwc.batch_command(cmd, ops)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shane/git/mongo-python-driver/pymongo/message.py", line 959, in batch_command
raise InvalidOperation("cannot do an empty bulk write")
pymongo.errors.InvalidOperation: cannot do an empty bulk write