-
Type: Bug
-
Resolution: Unresolved
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Python Drivers
Detailed steps to reproduce the problem?
server_selector is intended to be used to filter the list of selectable servers but it's api can be misused to inject new ServerDescription objects instead which can cause problems:
>>> def server_selector(servers):return [ServerDescription(address=servers[0].address)] ... >>> client = MongoClient(server_selector=server_selector) >>> client.admin.command('ping') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/shane/git/mongo-python-driver/pymongo/_csot.py", line 108, in csot_wrapper return func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/shane/git/mongo-python-driver/pymongo/database.py", line 893, in command with self.__client._conn_for_reads(read_preference, session, operation=command_name) as ( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/shane/git/mongo-python-driver/pymongo/mongo_client.py", line 1364, in _conn_for_reads server = self._select_server(read_preference, session, operation) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/shane/git/mongo-python-driver/pymongo/mongo_client.py", line 1311, in _select_server server = topology.select_server( ^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/shane/git/mongo-python-driver/pymongo/topology.py", line 359, in select_server server = self._select_server( ^^^^^^^^^^^^^^^^^^^^ File "/Users/shane/git/mongo-python-driver/pymongo/topology.py", line 337, in _select_server servers = self.select_servers( ^^^^^^^^^^^^^^^^^^^^ File "/Users/shane/git/mongo-python-driver/pymongo/topology.py", line 244, in select_servers server_descriptions = self._select_servers_loop( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/shane/git/mongo-python-driver/pymongo/topology.py", line 276, in _select_servers_loop server_descriptions = self._description.apply_selector( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/shane/git/mongo-python-driver/pymongo/topology_description.py", line 328, in apply_selector return self._apply_local_threshold(selection) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/shane/git/mongo-python-driver/pymongo/topology_description.py", line 271, in _apply_local_threshold return [ ^ File "/Users/shane/git/mongo-python-driver/pymongo/topology_description.py", line 274, in <listcomp> if (cast(float, s.round_trip_time) - fastest) <= threshold ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~ TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'
Definition of done: what must be done to consider the task complete?
server_selector should only be allow to return a subset of the ServerDescription instances it receives. If the return is not a subset, pymongo should raise a ConfigurationError.