From 0ca926ccfa32340819ad5232874cd1738421ca0a Mon Sep 17 00:00:00 2001 From: Iris <58442094+sleepyStick@users.noreply.github.com> Date: Thu, 12 Sep 2024 08:59:57 -0700 Subject: [PATCH 1/2] PYTHON-4753 [Build Failure] Async tests missing awaits (#1851) --- test/asynchronous/test_auth.py | 6 +++--- test/test_auth.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/asynchronous/test_auth.py b/test/asynchronous/test_auth.py index e516ff679..06f7fb9ca 100644 --- a/test/asynchronous/test_auth.py +++ b/test/asynchronous/test_auth.py @@ -169,7 +169,7 @@ class TestGSSAPI(unittest.IsolatedAsyncioTestCase): client = AsyncMongoClient(mech_uri) await client[GSSAPI_DB].collection.find_one() - set_name = await client.admin.command(HelloCompat.LEGACY_CMD).get("setName") + set_name = async_client_context.replica_set_name if set_name: if not self.service_realm_required: # Without authMechanismProperties @@ -242,7 +242,7 @@ class TestGSSAPI(unittest.IsolatedAsyncioTestCase): thread.join() self.assertTrue(thread.success) - set_name = await client.admin.command(HelloCompat.LEGACY_CMD).get("setName") + set_name = async_client_context.replica_set_name if set_name: client = AsyncMongoClient( GSSAPI_HOST, @@ -296,7 +296,7 @@ class TestSASLPlain(unittest.IsolatedAsyncioTestCase): client = AsyncMongoClient(uri) await client.ldap.test.find_one() - set_name = await client.admin.command(HelloCompat.LEGACY_CMD).get("setName") + set_name = async_client_context.replica_set_name if set_name: client = AsyncMongoClient( SASL_HOST, diff --git a/test/test_auth.py b/test/test_auth.py index 0bf0cfd80..fa3d0905b 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -169,7 +169,7 @@ class TestGSSAPI(unittest.TestCase): client = MongoClient(mech_uri) client[GSSAPI_DB].collection.find_one() - set_name = client.admin.command(HelloCompat.LEGACY_CMD).get("setName") + set_name = client_context.replica_set_name if set_name: if not self.service_realm_required: # Without authMechanismProperties @@ -242,7 +242,7 @@ class TestGSSAPI(unittest.TestCase): thread.join() self.assertTrue(thread.success) - set_name = client.admin.command(HelloCompat.LEGACY_CMD).get("setName") + set_name = client_context.replica_set_name if set_name: client = MongoClient( GSSAPI_HOST, @@ -296,7 +296,7 @@ class TestSASLPlain(unittest.TestCase): client = MongoClient(uri) client.ldap.test.find_one() - set_name = client.admin.command(HelloCompat.LEGACY_CMD).get("setName") + set_name = client_context.replica_set_name if set_name: client = MongoClient( SASL_HOST, From 9b9cf733682847136c867f192731dbd78fd8de61 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 12 Sep 2024 16:19:05 -0400 Subject: [PATCH 2/2] PYTHON-4758 - Only emit warnings for unclosed clients after opening (#1856) --- pymongo/asynchronous/mongo_client.py | 2 +- pymongo/synchronous/mongo_client.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pymongo/asynchronous/mongo_client.py b/pymongo/asynchronous/mongo_client.py index 9dba97d12..f7fc8e5e8 100644 --- a/pymongo/asynchronous/mongo_client.py +++ b/pymongo/asynchronous/mongo_client.py @@ -1185,7 +1185,7 @@ class AsyncMongoClient(common.BaseObject, Generic[_DocumentType]): def __del__(self) -> None: """Check that this AsyncMongoClient has been closed and issue a warning if not.""" try: - if not self._closed: + if self._opened and not self._closed: warnings.warn( ( f"Unclosed {type(self).__name__} opened at:\n{self._topology_settings._stack}" diff --git a/pymongo/synchronous/mongo_client.py b/pymongo/synchronous/mongo_client.py index 21fa57b5d..5786bbf5a 100644 --- a/pymongo/synchronous/mongo_client.py +++ b/pymongo/synchronous/mongo_client.py @@ -1185,7 +1185,7 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]): def __del__(self) -> None: """Check that this MongoClient has been closed and issue a warning if not.""" try: - if not self._closed: + if self._opened and not self._closed: warnings.warn( ( f"Unclosed {type(self).__name__} opened at:\n{self._topology_settings._stack}"