Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-4666

client.bulk_write does not properly check for large documents

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.9
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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
      

            Assignee:
            shruti.sridhar@mongodb.com Shruti Sridhar (Inactive)
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: