From e4751438bd5e87ce013d07ad76d993e08a86d932 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Fri, 2 May 2025 10:38:23 -0400 Subject: [PATCH 1/3] PYTHON-5371 - Skip test_continuous_network_errors when debug logs are enabled --- test/asynchronous/test_client.py | 1 + test/test_client.py | 1 + 2 files changed, 2 insertions(+) diff --git a/test/asynchronous/test_client.py b/test/asynchronous/test_client.py index 1e1faf0a2a..2e17318792 100644 --- a/test/asynchronous/test_client.py +++ b/test/asynchronous/test_client.py @@ -1906,6 +1906,7 @@ async def test_direct_connection(self): with self.assertRaises(ConfigurationError): AsyncMongoClient(["host1", "host2"], directConnection=True) + @unittest.skipIf(os.environ.get("DEBUG_LOG"), "Enabling debug logs breaks this test") @unittest.skipIf("PyPy" in sys.version, "PYTHON-2927 fails often on PyPy") async def test_continuous_network_errors(self): def server_description_count(): diff --git a/test/test_client.py b/test/test_client.py index 189e58e803..dbe93bfb12 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -1863,6 +1863,7 @@ def test_direct_connection(self): with self.assertRaises(ConfigurationError): MongoClient(["host1", "host2"], directConnection=True) + @unittest.skipIf(os.environ.get("DEBUG_LOG"), "Enabling debug logs breaks this test") @unittest.skipIf("PyPy" in sys.version, "PYTHON-2927 fails often on PyPy") def test_continuous_network_errors(self): def server_description_count(): From bd002b984a55ff8392e80bf39b1a7395d681ef78 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Fri, 2 May 2025 11:24:40 -0400 Subject: [PATCH 2/3] Pass ServerDescription.__repr__ to SDAM logging --- pymongo/asynchronous/topology.py | 16 ++++++++-------- pymongo/synchronous/topology.py | 16 ++++++++-------- test/asynchronous/test_client.py | 1 - test/test_client.py | 1 - 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/pymongo/asynchronous/topology.py b/pymongo/asynchronous/topology.py index 438dd1e352..93b0f527b7 100644 --- a/pymongo/asynchronous/topology.py +++ b/pymongo/asynchronous/topology.py @@ -154,8 +154,8 @@ def __init__(self, topology_settings: TopologySettings): _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=initial_td, - newDescription=self._description, + previousDescription=initial_td.__repr__(), + newDescription=self._description.__repr__(), ) for seed in topology_settings.seeds: @@ -514,8 +514,8 @@ async def _process_change( _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=td_old, - newDescription=self._description, + previousDescription=td_old.__repr__(), + newDescription=self._description.__repr__(), ) # Shutdown SRV polling for unsupported cluster types. @@ -581,8 +581,8 @@ async def _process_srv_update(self, seedlist: list[tuple[str, Any]]) -> None: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=td_old, - newDescription=self._description, + previousDescription=td_old.__repr__(), + newDescription=self._description.__repr__(), ) async def on_srv_update(self, seedlist: list[tuple[str, Any]]) -> None: @@ -747,8 +747,8 @@ async def close(self) -> None: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=old_td, - newDescription=self._description, + previousDescription=old_td.__repr__(), + newDescription=self._description.__repr__(), ) _debug_log( _SDAM_LOGGER, message=_SDAMStatusMessage.STOP_TOPOLOGY, topologyId=self._topology_id diff --git a/pymongo/synchronous/topology.py b/pymongo/synchronous/topology.py index 1e99adf726..a5c1cc4d57 100644 --- a/pymongo/synchronous/topology.py +++ b/pymongo/synchronous/topology.py @@ -154,8 +154,8 @@ def __init__(self, topology_settings: TopologySettings): _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=initial_td, - newDescription=self._description, + previousDescription=initial_td.__repr__(), + newDescription=self._description.__repr__(), ) for seed in topology_settings.seeds: @@ -514,8 +514,8 @@ def _process_change( _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=td_old, - newDescription=self._description, + previousDescription=td_old.__repr__(), + newDescription=self._description.__repr__(), ) # Shutdown SRV polling for unsupported cluster types. @@ -581,8 +581,8 @@ def _process_srv_update(self, seedlist: list[tuple[str, Any]]) -> None: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=td_old, - newDescription=self._description, + previousDescription=td_old.__repr__(), + newDescription=self._description.__repr__(), ) def on_srv_update(self, seedlist: list[tuple[str, Any]]) -> None: @@ -745,8 +745,8 @@ def close(self) -> None: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=old_td, - newDescription=self._description, + previousDescription=old_td.__repr__(), + newDescription=self._description.__repr__(), ) _debug_log( _SDAM_LOGGER, message=_SDAMStatusMessage.STOP_TOPOLOGY, topologyId=self._topology_id diff --git a/test/asynchronous/test_client.py b/test/asynchronous/test_client.py index 2e17318792..1e1faf0a2a 100644 --- a/test/asynchronous/test_client.py +++ b/test/asynchronous/test_client.py @@ -1906,7 +1906,6 @@ async def test_direct_connection(self): with self.assertRaises(ConfigurationError): AsyncMongoClient(["host1", "host2"], directConnection=True) - @unittest.skipIf(os.environ.get("DEBUG_LOG"), "Enabling debug logs breaks this test") @unittest.skipIf("PyPy" in sys.version, "PYTHON-2927 fails often on PyPy") async def test_continuous_network_errors(self): def server_description_count(): diff --git a/test/test_client.py b/test/test_client.py index dbe93bfb12..189e58e803 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -1863,7 +1863,6 @@ def test_direct_connection(self): with self.assertRaises(ConfigurationError): MongoClient(["host1", "host2"], directConnection=True) - @unittest.skipIf(os.environ.get("DEBUG_LOG"), "Enabling debug logs breaks this test") @unittest.skipIf("PyPy" in sys.version, "PYTHON-2927 fails often on PyPy") def test_continuous_network_errors(self): def server_description_count(): From 221d9e55fff849dc584b2b346f457a4cf0001f3c Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 8 May 2025 14:05:40 -0400 Subject: [PATCH 3/3] Use repr() --- pymongo/asynchronous/topology.py | 16 ++++++++-------- pymongo/synchronous/topology.py | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pymongo/asynchronous/topology.py b/pymongo/asynchronous/topology.py index 93b0f527b7..99b30fed1e 100644 --- a/pymongo/asynchronous/topology.py +++ b/pymongo/asynchronous/topology.py @@ -154,8 +154,8 @@ def __init__(self, topology_settings: TopologySettings): _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=initial_td.__repr__(), - newDescription=self._description.__repr__(), + previousDescription=repr(initial_td), + newDescription=repr(self._description), ) for seed in topology_settings.seeds: @@ -514,8 +514,8 @@ async def _process_change( _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=td_old.__repr__(), - newDescription=self._description.__repr__(), + previousDescription=repr(td_old), + newDescription=repr(self._description), ) # Shutdown SRV polling for unsupported cluster types. @@ -581,8 +581,8 @@ async def _process_srv_update(self, seedlist: list[tuple[str, Any]]) -> None: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=td_old.__repr__(), - newDescription=self._description.__repr__(), + previousDescription=repr(td_old), + newDescription=repr(self._description), ) async def on_srv_update(self, seedlist: list[tuple[str, Any]]) -> None: @@ -747,8 +747,8 @@ async def close(self) -> None: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=old_td.__repr__(), - newDescription=self._description.__repr__(), + previousDescription=repr(old_td), + newDescription=repr(self._description), ) _debug_log( _SDAM_LOGGER, message=_SDAMStatusMessage.STOP_TOPOLOGY, topologyId=self._topology_id diff --git a/pymongo/synchronous/topology.py b/pymongo/synchronous/topology.py index a5c1cc4d57..10d41def6e 100644 --- a/pymongo/synchronous/topology.py +++ b/pymongo/synchronous/topology.py @@ -154,8 +154,8 @@ def __init__(self, topology_settings: TopologySettings): _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=initial_td.__repr__(), - newDescription=self._description.__repr__(), + previousDescription=repr(initial_td), + newDescription=repr(self._description), ) for seed in topology_settings.seeds: @@ -514,8 +514,8 @@ def _process_change( _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=td_old.__repr__(), - newDescription=self._description.__repr__(), + previousDescription=repr(td_old), + newDescription=repr(self._description), ) # Shutdown SRV polling for unsupported cluster types. @@ -581,8 +581,8 @@ def _process_srv_update(self, seedlist: list[tuple[str, Any]]) -> None: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=td_old.__repr__(), - newDescription=self._description.__repr__(), + previousDescription=repr(td_old), + newDescription=repr(self._description), ) def on_srv_update(self, seedlist: list[tuple[str, Any]]) -> None: @@ -745,8 +745,8 @@ def close(self) -> None: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=old_td.__repr__(), - newDescription=self._description.__repr__(), + previousDescription=repr(old_td), + newDescription=repr(self._description), ) _debug_log( _SDAM_LOGGER, message=_SDAMStatusMessage.STOP_TOPOLOGY, topologyId=self._topology_id