Skip to content

Commit d2a842d

Browse files
committed
PYTHON-5745 Add _topology_id property to MongoClient
1 parent 541e039 commit d2a842d

4 files changed

Lines changed: 16 additions & 8 deletions

File tree

pymongo/asynchronous/command_runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ async def run_bulk_write_command(
245245
:param max_doc_size: The largest document size in the batch, passed to ``conn.send_message``.
246246
:param unacknowledged: When ``True``, send only and fake an ``{"ok": 1}`` reply.
247247
"""
248-
topology_id = client._topology_settings._topology_id if client is not None else None
248+
topology_id = client._topology_id if client is not None else None
249249
return await _run_command(
250250
bwc.conn, # type: ignore[arg-type]
251251
cmd,
@@ -305,7 +305,7 @@ async def run_cursor_command(
305305
reply's own ``unpack_response`` is used.
306306
:param cursor_id: The cursor id passed to ``unpack_res``.
307307
"""
308-
topology_id = client._topology_settings._topology_id if client is not None else None
308+
topology_id = client._topology_id if client is not None else None
309309
return await _run_command(
310310
conn,
311311
cmd,
@@ -389,7 +389,7 @@ async def run_command(
389389
if collation is not None:
390390
spec["collation"] = collation
391391

392-
topology_id = client._topology_settings._topology_id if client is not None else None
392+
topology_id = client._topology_id if client is not None else None
393393
speculative_hello = _is_speculative_authenticate(name, spec)
394394

395395
if compression_ctx and name.lower() in _NO_COMPRESSION:

pymongo/asynchronous/mongo_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,10 @@ def topology_description(self) -> TopologyDescription:
12481248
)
12491249
return self._topology.description
12501250

1251+
@property
1252+
def _topology_id(self) -> Optional[ObjectId]:
1253+
return self._topology_settings._topology_id
1254+
12511255
@property
12521256
def nodes(self) -> frozenset[_Address]:
12531257
"""Set of all currently connected servers.
@@ -3012,7 +3016,7 @@ async def _write(self) -> T:
30123016
_debug_log(
30133017
_COMMAND_LOGGER,
30143018
message=f"Retrying write attempt number {self._attempt_number}",
3015-
clientId=self._client._topology_settings._topology_id,
3019+
clientId=self._client._topology_id,
30163020
commandName=self._operation,
30173021
operationId=self._operation_id,
30183022
)

pymongo/synchronous/command_runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def run_bulk_write_command(
245245
:param max_doc_size: The largest document size in the batch, passed to ``conn.send_message``.
246246
:param unacknowledged: When ``True``, send only and fake an ``{"ok": 1}`` reply.
247247
"""
248-
topology_id = client._topology_settings._topology_id if client is not None else None
248+
topology_id = client._topology_id if client is not None else None
249249
return _run_command(
250250
bwc.conn, # type: ignore[arg-type]
251251
cmd,
@@ -305,7 +305,7 @@ def run_cursor_command(
305305
reply's own ``unpack_response`` is used.
306306
:param cursor_id: The cursor id passed to ``unpack_res``.
307307
"""
308-
topology_id = client._topology_settings._topology_id if client is not None else None
308+
topology_id = client._topology_id if client is not None else None
309309
return _run_command(
310310
conn,
311311
cmd,
@@ -389,7 +389,7 @@ def run_command(
389389
if collation is not None:
390390
spec["collation"] = collation
391391

392-
topology_id = client._topology_settings._topology_id if client is not None else None
392+
topology_id = client._topology_id if client is not None else None
393393
speculative_hello = _is_speculative_authenticate(name, spec)
394394

395395
if compression_ctx and name.lower() in _NO_COMPRESSION:

pymongo/synchronous/mongo_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,10 @@ def topology_description(self) -> TopologyDescription:
12491249
)
12501250
return self._topology.description
12511251

1252+
@property
1253+
def _topology_id(self) -> Optional[ObjectId]:
1254+
return self._topology_settings._topology_id
1255+
12521256
@property
12531257
def nodes(self) -> frozenset[_Address]:
12541258
"""Set of all currently connected servers.
@@ -3003,7 +3007,7 @@ def _write(self) -> T:
30033007
_debug_log(
30043008
_COMMAND_LOGGER,
30053009
message=f"Retrying write attempt number {self._attempt_number}",
3006-
clientId=self._client._topology_settings._topology_id,
3010+
clientId=self._client._topology_id,
30073011
commandName=self._operation,
30083012
operationId=self._operation_id,
30093013
)

0 commit comments

Comments
 (0)