Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions pymongo/asynchronous/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1453,13 +1453,6 @@ async def address(self) -> Optional[tuple[str, int]]:
'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
Copy link
Member

@ShaneHarvey ShaneHarvey Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe returning None when the TOPOLOGY_TYPE is ReplicaSetNoPrimary was intentional and should be reinstated. This also warrants a note in the changelog and a .. versionchanged::...

return await self._server_property("address")

@property
Expand Down
7 changes: 0 additions & 7 deletions pymongo/synchronous/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,13 +1447,6 @@ def address(self) -> Optional[tuple[str, int]]:
'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
Expand Down
2 changes: 0 additions & 2 deletions test/asynchronous/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,6 @@ async def test_init_disconnected(self):
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)
Expand Down
2 changes: 0 additions & 2 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,6 @@ def test_init_disconnected(self):
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)
Expand Down
3 changes: 2 additions & 1 deletion test/test_replica_set_reconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def test_client(self):

with self.assertRaises(ServerSelectionTimeoutError):
c.db.command("ping")
self.assertEqual(c.address, None)
with self.assertRaises(ServerSelectionTimeoutError):
_ = c.address
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning None here was intentional behavior.


# Client can still discover the primary node
c.revive_host("a:1")
Expand Down
Loading