From 167b9648caf94d57ee618ed240d7910f4553b55e Mon Sep 17 00:00:00 2001 From: Alessio Castrica <64859146+Ale-Cas@users.noreply.github.com> Date: Thu, 4 Apr 2024 21:57:07 +0200 Subject: [PATCH] PYTHON-4298 Raise ConfigurationError not TypeError when round_trip_time is None in server selection (#1566) Co-authored-by: Alessio --- pymongo/topology_description.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pymongo/topology_description.py b/pymongo/topology_description.py index 99243d7ce..cc2330cba 100644 --- a/pymongo/topology_description.py +++ b/pymongo/topology_description.py @@ -265,8 +265,14 @@ class TopologyDescription: def _apply_local_threshold(self, selection: Optional[Selection]) -> list[ServerDescription]: if not selection: return [] + round_trip_times: list[float] = [] + for server in selection.server_descriptions: + if server.round_trip_time is None: + config_err_msg = f"round_trip_time for server {server.address} is unexpectedly None: {self}, servers: {selection.server_descriptions}" + raise ConfigurationError(config_err_msg) + round_trip_times.append(server.round_trip_time) # Round trip time in seconds. - fastest = min(cast(float, s.round_trip_time) for s in selection.server_descriptions) + fastest = min(round_trip_times) threshold = self._topology_settings.local_threshold_ms / 1000.0 return [ s