PYTHON-4870 - MongoClient.address should block until a connection suc… (#1929)

This commit is contained in:
Noah Stapp 2024-10-15 12:12:18 -04:00 committed by GitHub
parent 872fda179e
commit 710bc40c73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 2 additions and 19 deletions

View File

@ -1453,13 +1453,6 @@ class AsyncMongoClient(common.BaseObject, Generic[_DocumentType]):
'Cannot use "address" property when load balancing among'
' mongoses, use "nodes" instead.'
)
if topology_type not in (
TOPOLOGY_TYPE.ReplicaSetWithPrimary,
TOPOLOGY_TYPE.Single,
TOPOLOGY_TYPE.LoadBalanced,
TOPOLOGY_TYPE.Sharded,
):
return None
return await self._server_property("address")
@property

View File

@ -1447,13 +1447,6 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]):
'Cannot use "address" property when load balancing among'
' mongoses, use "nodes" instead.'
)
if topology_type not in (
TOPOLOGY_TYPE.ReplicaSetWithPrimary,
TOPOLOGY_TYPE.Single,
TOPOLOGY_TYPE.LoadBalanced,
TOPOLOGY_TYPE.Sharded,
):
return None
return self._server_property("address")
@property

View File

@ -838,8 +838,6 @@ class TestClient(AsyncIntegrationTest):
c = await self.async_rs_or_single_client(connect=False)
self.assertIsInstance(c.topology_description, TopologyDescription)
self.assertEqual(c.topology_description, c._topology._description)
self.assertIsNone(await c.address) # PYTHON-2981
await c.admin.command("ping") # connect
if async_client_context.is_rs:
# The primary's host and port are from the replica set config.
self.assertIsNotNone(await c.address)

View File

@ -812,8 +812,6 @@ class TestClient(IntegrationTest):
c = self.rs_or_single_client(connect=False)
self.assertIsInstance(c.topology_description, TopologyDescription)
self.assertEqual(c.topology_description, c._topology._description)
self.assertIsNone(c.address) # PYTHON-2981
c.admin.command("ping") # connect
if client_context.is_rs:
# The primary's host and port are from the replica set config.
self.assertIsNotNone(c.address)

View File

@ -59,7 +59,8 @@ class TestSecondaryBecomesStandalone(MockClientTest):
with self.assertRaises(ServerSelectionTimeoutError):
c.db.command("ping")
self.assertEqual(c.address, None)
with self.assertRaises(ServerSelectionTimeoutError):
_ = c.address
# Client can still discover the primary node
c.revive_host("a:1")