From 5914ea0ff42b4bbacdb172f8b55321726553472f Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 8 May 2025 13:10:11 -0500 Subject: [PATCH 1/4] PYTHON-5342 Fix test_dns_failures test (#2336) --- test/asynchronous/test_srv_polling.py | 5 +++-- test/test_srv_polling.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/asynchronous/test_srv_polling.py b/test/asynchronous/test_srv_polling.py index b40aa90cf..3ba50e77a 100644 --- a/test/asynchronous/test_srv_polling.py +++ b/test/asynchronous/test_srv_polling.py @@ -20,7 +20,6 @@ import sys import time from test.utils_shared import FunctionCallRecorder from typing import Any -from unittest import skipIf sys.path[0:0] = [""] @@ -92,7 +91,6 @@ class SrvPollingKnobs: self.disable() -@skipIf(not _IS_SYNC and sys.platform == "win32", "PYTHON-5342 known issue on Windows") class TestSrvPolling(AsyncPyMongoTestCase): BASE_SRV_RESPONSE = [ ("localhost.test.build.10gen.cc", 27017), @@ -186,6 +184,9 @@ class TestSrvPolling(AsyncPyMongoTestCase): ): await assertion_method(expected_response, client) + # Close the client early to avoid affecting the next scenario run. + await client.close() + async def test_addition(self): response = self.BASE_SRV_RESPONSE[:] response.append(("localhost.test.build.10gen.cc", 27019)) diff --git a/test/test_srv_polling.py b/test/test_srv_polling.py index 0d84d4124..971c3bad5 100644 --- a/test/test_srv_polling.py +++ b/test/test_srv_polling.py @@ -20,7 +20,6 @@ import sys import time from test.utils_shared import FunctionCallRecorder from typing import Any -from unittest import skipIf sys.path[0:0] = [""] @@ -92,7 +91,6 @@ class SrvPollingKnobs: self.disable() -@skipIf(not _IS_SYNC and sys.platform == "win32", "PYTHON-5342 known issue on Windows") class TestSrvPolling(PyMongoTestCase): BASE_SRV_RESPONSE = [ ("localhost.test.build.10gen.cc", 27017), @@ -186,6 +184,9 @@ class TestSrvPolling(PyMongoTestCase): ): assertion_method(expected_response, client) + # Close the client early to avoid affecting the next scenario run. + client.close() + def test_addition(self): response = self.BASE_SRV_RESPONSE[:] response.append(("localhost.test.build.10gen.cc", 27019)) From 775b6832769a32752ef998dc84eb37c3cf52ca59 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 8 May 2025 14:20:11 -0400 Subject: [PATCH 2/4] PYTHON-5371 - Pass repr(ServerDescription) to logging (#2329) --- 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 438dd1e35..99b30fed1 100644 --- a/pymongo/asynchronous/topology.py +++ b/pymongo/asynchronous/topology.py @@ -154,8 +154,8 @@ class Topology: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=initial_td, - newDescription=self._description, + previousDescription=repr(initial_td), + newDescription=repr(self._description), ) for seed in topology_settings.seeds: @@ -514,8 +514,8 @@ class Topology: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=td_old, - newDescription=self._description, + previousDescription=repr(td_old), + newDescription=repr(self._description), ) # Shutdown SRV polling for unsupported cluster types. @@ -581,8 +581,8 @@ class Topology: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=td_old, - newDescription=self._description, + previousDescription=repr(td_old), + newDescription=repr(self._description), ) async def on_srv_update(self, seedlist: list[tuple[str, Any]]) -> None: @@ -747,8 +747,8 @@ class Topology: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=old_td, - newDescription=self._description, + 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 1e99adf72..10d41def6 100644 --- a/pymongo/synchronous/topology.py +++ b/pymongo/synchronous/topology.py @@ -154,8 +154,8 @@ class Topology: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=initial_td, - newDescription=self._description, + previousDescription=repr(initial_td), + newDescription=repr(self._description), ) for seed in topology_settings.seeds: @@ -514,8 +514,8 @@ class Topology: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=td_old, - newDescription=self._description, + previousDescription=repr(td_old), + newDescription=repr(self._description), ) # Shutdown SRV polling for unsupported cluster types. @@ -581,8 +581,8 @@ class Topology: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=td_old, - newDescription=self._description, + previousDescription=repr(td_old), + newDescription=repr(self._description), ) def on_srv_update(self, seedlist: list[tuple[str, Any]]) -> None: @@ -745,8 +745,8 @@ class Topology: _SDAM_LOGGER, message=_SDAMStatusMessage.TOPOLOGY_CHANGE, topologyId=self._topology_id, - previousDescription=old_td, - newDescription=self._description, + previousDescription=repr(old_td), + newDescription=repr(self._description), ) _debug_log( _SDAM_LOGGER, message=_SDAMStatusMessage.STOP_TOPOLOGY, topologyId=self._topology_id From 98b030af947537b34ed5c11c20b763057632d37a Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 8 May 2025 15:19:31 -0400 Subject: [PATCH 3/4] PYTHON-5356 - Init unified test client SDAM for all unified tests (#2325) --- test/asynchronous/unified_format.py | 1 + test/unified_format.py | 1 + 2 files changed, 2 insertions(+) diff --git a/test/asynchronous/unified_format.py b/test/asynchronous/unified_format.py index 10b247d1f..23707b942 100644 --- a/test/asynchronous/unified_format.py +++ b/test/asynchronous/unified_format.py @@ -303,6 +303,7 @@ class EntityMapUtil: if uri: kwargs["h"] = uri client = await self.test.async_rs_or_single_client(**kwargs) + await client.aconnect() self[spec["id"]] = client return elif entity_type == "database": diff --git a/test/unified_format.py b/test/unified_format.py index d3da2b3a8..84881800a 100644 --- a/test/unified_format.py +++ b/test/unified_format.py @@ -302,6 +302,7 @@ class EntityMapUtil: if uri: kwargs["h"] = uri client = self.test.rs_or_single_client(**kwargs) + client._connect() self[spec["id"]] = client return elif entity_type == "database": From 2655bb4d864daeeb73cd5af0c5499c6a0874b590 Mon Sep 17 00:00:00 2001 From: "Jeffrey A. Clark" Date: Thu, 8 May 2025 17:14:26 -0400 Subject: [PATCH 4/4] PYTHON-5033 Use PyModule_Add on >= 3.13 (#2332) --- bson/_cbsonmodule.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bson/_cbsonmodule.c b/bson/_cbsonmodule.c index 672f5eeda..be91e4173 100644 --- a/bson/_cbsonmodule.c +++ b/bson/_cbsonmodule.c @@ -3227,11 +3227,18 @@ _cbson_exec(PyObject *m) INITERROR; } +#if PY_VERSION_HEX >= 0x030D0000 + if (PyModule_Add(m, "_C_API", c_api_object) < 0) { + Py_DECREF(m); + INITERROR; + } +# else if (PyModule_AddObject(m, "_C_API", c_api_object) < 0) { Py_DECREF(c_api_object); Py_DECREF(m); INITERROR; } +#endif return 0; }