Skip to content

PYTHON-4667 Handle $clusterTime from error responses in client Bulk Write #1822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions pymongo/asynchronous/client_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ async def write_command(
bwc._fail(request_id, failure, duration)
# Top-level error will be embedded in ClientBulkWriteException.
reply = {"error": exc}
# Propagate $clusterTime to the caller.
if "$clusterTime" in cmd:
reply["$clusterTime"] = cmd["$clusterTime"]
Copy link
Member

Choose a reason for hiding this comment

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

$clusterTime needs to be parsed from the (potential) server error response, not the command. We also need to do the same for operationTime.

This is the method that handles it, it probably makes more sense to call this method at a lower level if we can (perhaps in write_command):

client._process_response(command_response, session)

Or another alternative.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense, updated.

finally:
bwc.start_time = datetime.datetime.now()
return reply # type: ignore[return-value]
Expand Down
3 changes: 3 additions & 0 deletions pymongo/synchronous/client_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ def write_command(
bwc._fail(request_id, failure, duration)
# Top-level error will be embedded in ClientBulkWriteException.
reply = {"error": exc}
# Propagate $clusterTime to the caller.
if "$clusterTime" in cmd:
reply["$clusterTime"] = cmd["$clusterTime"]
finally:
bwc.start_time = datetime.datetime.now()
return reply # type: ignore[return-value]
Expand Down
Loading