Skip to content

Commit 167b964

Browse files
Ale-CasAlessio
andauthored
PYTHON-4298 Raise ConfigurationError not TypeError when round_trip_time is None in server selection (#1566)
Co-authored-by: Alessio <[email protected]>
1 parent 1e0ef67 commit 167b964

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pymongo/topology_description.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,14 @@ def srv_max_hosts(self) -> int:
265265
def _apply_local_threshold(self, selection: Optional[Selection]) -> list[ServerDescription]:
266266
if not selection:
267267
return []
268+
round_trip_times: list[float] = []
269+
for server in selection.server_descriptions:
270+
if server.round_trip_time is None:
271+
config_err_msg = f"round_trip_time for server {server.address} is unexpectedly None: {self}, servers: {selection.server_descriptions}"
272+
raise ConfigurationError(config_err_msg)
273+
round_trip_times.append(server.round_trip_time)
268274
# Round trip time in seconds.
269-
fastest = min(cast(float, s.round_trip_time) for s in selection.server_descriptions)
275+
fastest = min(round_trip_times)
270276
threshold = self._topology_settings.local_threshold_ms / 1000.0
271277
return [
272278
s

0 commit comments

Comments
 (0)