-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-4924 - PoolClearedError should have TransientTransactionError … #2244
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
Conversation
…label appended to it
pymongo/asynchronous/pool.py
Outdated
@@ -190,6 +190,10 @@ def _raise_connection_failure( | |||
) -> NoReturn: | |||
"""Convert a socket.error to ConnectionFailure and raise it.""" | |||
host, port = address | |||
if isinstance(error, PyMongoError) and error._error_labels: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need any pymongo changes here. We already add the error label to PoolClearedErrors here:
exc_val._add_error_label("TransientTransactionError") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we expect the added test to still pass without the code changes then? It fails without these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That test should fail because we only add the TransientTransactionError if we're actually running a transaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, got it. We can go ahead and close this PR and ticket it sounds like then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm that we have a test for "pool clear error" having the label in a txn? If not we should add one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our Start Transactions Retry Example 1
section of TestTransactionExamples
in test_examples.py
refers to the label, but I don't think it is intended to fail every time and check for the label:
mongo-python-driver/test/asynchronous/test_examples.py
Lines 1007 to 1021 in 58a41ae
async def run_transaction_with_retry(txn_func, session): | |
while True: | |
try: | |
await txn_func(session) # performs transaction | |
break | |
except (ConnectionFailure, OperationFailure) as exc: | |
print("Transaction aborted. Caught exception during transaction.") | |
# If transient error, retry the whole transaction | |
if exc.has_error_label("TransientTransactionError"): | |
print("TransientTransactionError, retrying transaction ...") | |
continue | |
else: | |
raise | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need that new tests added in this PR.
pymongo/asynchronous/pool.py
Outdated
@@ -190,6 +190,10 @@ def _raise_connection_failure( | |||
) -> NoReturn: | |||
"""Convert a socket.error to ConnectionFailure and raise it.""" | |||
host, port = address | |||
if isinstance(error, PyMongoError) and error._error_labels: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need that new tests added in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
…label appended to it