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

Raise informative error when server_description.round_trip_time is None in server selection

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.7
    • 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?

      https://github.com/mongodb/mongo-python-driver/pull/1361 outlines an unexpected error case where a server description is in an unknown state but is attempting to access its round_trip_time. This behavior should result in a more useful error that contains the server description states.

      Here's an example:

      for doc in collection.find(
        File "/opt/venv/lib/python3.8/site-packages/pymongo/cursor.py", line 1264, in next
          if len(self.__data) or self._refresh():
        File "/opt/venv/lib/python3.8/site-packages/pymongo/cursor.py", line 1181, in _refresh
          self.__send_message(q)
        File "/opt/venv/lib/python3.8/site-packages/pymongo/cursor.py", line 1060, in __send_message
          response = client._run_operation(
        File "/opt/venv/lib/python3.8/site-packages/pymongo/_csot.py", line 107, in csot_wrapper
          return func(self, *args, **kwargs)
        File "/opt/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1394, in _run_operation
          return self._retryable_read(
        File "/opt/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1492, in _retryable_read
          return self._retry_internal(
        File "/opt/venv/lib/python3.8/site-packages/pymongo/_csot.py", line 107, in csot_wrapper
          return func(self, *args, **kwargs)
        File "/opt/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1453, in _retry_internal
          return _ClientConnectionRetryable(
        File "/opt/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 2315, in run
          return self._read() if self._is_read else self._write()
        File "/opt/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 2437, in _read
          self._server = self._get_server()
        File "/opt/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 2400, in _get_server
          return self._client._select_server(
        File "/opt/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1303, in _select_server
          server = topology.select_server(server_selector)
        File "/opt/venv/lib/python3.8/site-packages/pymongo/topology.py", line 302, in select_server
          server = self._select_server(selector, server_selection_timeout, address)
        File "/opt/venv/lib/python3.8/site-packages/pymongo/topology.py", line 286, in _select_server
          servers = self.select_servers(selector, server_selection_timeout, address)
        File "/opt/venv/lib/python3.8/site-packages/pymongo/topology.py", line 237, in select_servers
          server_descriptions = self._select_servers_loop(selector, server_timeout, address)
        File "/opt/venv/lib/python3.8/site-packages/pymongo/topology.py", line 252, in _select_servers_loop
          server_descriptions = self._description.apply_selector(
        File "/opt/venv/lib/python3.8/site-packages/pymongo/topology_description.py", line 330, in apply_selector
          return self._apply_local_threshold(selection)
        File "/opt/venv/lib/python3.8/site-packages/pymongo/topology_description.py", line 272, in _apply_local_threshold
          return [
        File "/opt/venv/lib/python3.8/site-packages/pymongo/topology_description.py", line 275, in <listcomp>
          if (cast(float, s.round_trip_time) - fastest) <= threshold
      TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'
      

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            noah.stapp@mongodb.com Noah Stapp
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: