Skip to content

Conversation

NoahStapp
Copy link
Contributor

…label appended to it

@NoahStapp NoahStapp requested a review from ShaneHarvey March 28, 2025 14:48
) -> NoReturn:
"""Convert a socket.error to ConnectionFailure and raise it."""
host, port = address
if isinstance(error, PyMongoError) and error._error_labels:
Copy link
Member

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")

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@ShaneHarvey ShaneHarvey Mar 28, 2025

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.

Copy link
Contributor Author

@NoahStapp NoahStapp Mar 31, 2025

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:

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

Copy link
Member

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.

@NoahStapp NoahStapp requested a review from ShaneHarvey April 7, 2025 18:19
) -> NoReturn:
"""Convert a socket.error to ConnectionFailure and raise it."""
host, port = address
if isinstance(error, PyMongoError) and error._error_labels:
Copy link
Member

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.

@NoahStapp NoahStapp requested a review from ShaneHarvey April 7, 2025 21:13
@ShaneHarvey ShaneHarvey requested a review from Copilot April 7, 2025 21:21
Copy link

@Copilot Copilot AI left a 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.

@NoahStapp NoahStapp merged commit bc2cc1e into mongodb:master Apr 8, 2025
34 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants