Uploaded image for project: 'Motor'
  1. Motor
  2. MOTOR-1317

AsyncIOMotorCursor.to_list() raises exception on empty TimeSeries collection

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: 3.4
    • Component/s: asyncio
    • None
    • Python Drivers

      Running AsyncIOMotorCursor.to_list() on an empty Timeseries Collection raises an error. I've tried it on a empty cursor and that was fine. The bug seems to be in empty Timeseries collection.

      Mongo version:

       

      db version v7.0.9
      Build Info: {
          "version": "7.0.9",
          "gitVersion": "3ff3a3925c36ed277cf5eafca5495f2e3728dd67",
          "openSSLVersion": "OpenSSL 3.0.2 15 Mar 2022",
          "modules": [
              "enterprise"
          ],
          "allocator": "tcmalloc",
          "environment": {
              "distmod": "ubuntu2204",
              "distarch": "x86_64",
              "target_arch": "x86_64"
          }
      }
       

       

       

      My code:

       

      cursor = main_db.db[collection_name].find(filter_query)
      while records := await cursor.to_list(100):
          await dev_db.db[collection_name].bulk_write(
              requests=[pymongo.InsertOne(document=record) for record in records],
              ordered=False) 

       

      Result:

       

      Traceback (most recent call last):
        File "F:\Agroture\ia-panel-backend\src\jobs\dev_db\job.py", line 114, in <module>
          asyncio.run(
        File "C:\Program Files\Python312\Lib\asyncio\runners.py", line 194, in run
          return runner.run(main)
                 ^^^^^^^^^^^^^^^^
        File "C:\Program Files\Python312\Lib\asyncio\runners.py", line 118, in run
          return self._loop.run_until_complete(task)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Program Files\Python312\Lib\asyncio\base_events.py", line 684, in run_until_complete
          return future.result()
                 ^^^^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\src\jobs\dev_db\job.py", line 80, in sync
          await sync_collection(
        File "F:\Agroture\ia-panel-backend\src\jobs\dev_db\job.py", line 21, in sync_collection
          while records := await cursor.to_list(100):
                           ^^^^^^^^^^^^^^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\motor\core.py", line 1683, in _to_list
          result = get_more_result.result()
                   ^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Program Files\Python312\Lib\concurrent\futures\thread.py", line 58, in run
          result = self.fn(*self.args, **self.kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\cursor.py", line 1181, in _refresh
          self.__send_message(q)
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\cursor.py", line 1060, in __send_message
          response = client._run_operation(
                     ^^^^^^^^^^^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\_csot.py", line 107, in csot_wrapper
          return func(self, *args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\mongo_client.py", line 1394, in _run_operation
          return self._retryable_read(
                 ^^^^^^^^^^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\mongo_client.py", line 1492, in _retryable_read
          return self._retry_internal(
                 ^^^^^^^^^^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\_csot.py", line 107, in csot_wrapper
          return func(self, *args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\mongo_client.py", line 1462, in _retry_internal
          ).run()
            ^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\mongo_client.py", line 2315, in run
          return self._read() if self._is_read else self._write()
                 ^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\mongo_client.py", line 2445, in _read
          return self._func(self._session, self._server, conn, read_pref)  # type: ignore
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\mongo_client.py", line 1390, in _cmd
          return server.run_operation(
                 ^^^^^^^^^^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\helpers.py", line 322, in inner
          return func(*args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\server.py", line 130, in run_operation
          message = operation.get_message(read_preference, conn, use_cmd)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\message.py", line 426, in get_message
          request_id, msg, size, _ = _op_msg(
                                     ^^^^^^^^
        File "F:\Agroture\ia-panel-backend\venv\Lib\site-packages\pymongo\message.py", line 762, in _op_msg
          return _op_msg_uncompressed(flags, command, identifier, docs, opts)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      bson.errors.InvalidDocument: cannot encode object: <Future finished result=[]>, of type: <class '_asyncio.Future'> 

       

       

            Assignee:
            noah.stapp@mongodb.com Noah Stapp
            Reporter:
            amirrezahamzavi2000@gmail.com Amirreza Hamzavi
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: