PYTHON-5505 Use proper RetryableError and SystemOverloadedError labels

This commit is contained in:
Shane Harvey 2025-08-26 15:45:06 -07:00
parent 875c5640d7
commit c458379522
6 changed files with 30 additions and 30 deletions

View File

@ -177,11 +177,11 @@ def _retry_overload(func: F) -> F:
await retry_policy.record_success(retry=attempt > 0)
return res
except PyMongoError as exc:
if not exc.has_error_label("Retryable"):
if not exc.has_error_label("RetryableError"):
raise
attempt += 1
delay = 0
if exc.has_error_label("SystemOverloaded"):
if exc.has_error_label("SystemOverloadedError"):
delay = retry_policy.backoff(attempt)
if not await retry_policy.should_retry(attempt, delay):
raise

View File

@ -2802,8 +2802,8 @@ class _ClientConnectionRetryable(Generic[T]):
if isinstance(exc, (ConnectionFailure, OperationFailure)):
# ConnectionFailures do not supply a code property
exc_code = getattr(exc, "code", None)
always_retryable = exc.has_error_label("Retryable")
overloaded = exc.has_error_label("SystemOverloaded")
always_retryable = exc.has_error_label("RetryableError")
overloaded = exc.has_error_label("SystemOverloadedError")
if not always_retryable and (
self._is_not_eligible_for_retry()
or (
@ -2825,8 +2825,8 @@ class _ClientConnectionRetryable(Generic[T]):
):
exc_to_check = exc.error
retryable_write_label = exc_to_check.has_error_label("RetryableWriteError")
always_retryable = exc_to_check.has_error_label("Retryable")
overloaded = exc_to_check.has_error_label("SystemOverloaded")
always_retryable = exc_to_check.has_error_label("RetryableError")
overloaded = exc_to_check.has_error_label("SystemOverloadedError")
if not self._retryable and not always_retryable:
raise
if retryable_write_label or always_retryable:

View File

@ -177,11 +177,11 @@ def _retry_overload(func: F) -> F:
retry_policy.record_success(retry=attempt > 0)
return res
except PyMongoError as exc:
if not exc.has_error_label("Retryable"):
if not exc.has_error_label("RetryableError"):
raise
attempt += 1
delay = 0
if exc.has_error_label("SystemOverloaded"):
if exc.has_error_label("SystemOverloadedError"):
delay = retry_policy.backoff(attempt)
if not retry_policy.should_retry(attempt, delay):
raise

View File

@ -2792,8 +2792,8 @@ class _ClientConnectionRetryable(Generic[T]):
if isinstance(exc, (ConnectionFailure, OperationFailure)):
# ConnectionFailures do not supply a code property
exc_code = getattr(exc, "code", None)
always_retryable = exc.has_error_label("Retryable")
overloaded = exc.has_error_label("SystemOverloaded")
always_retryable = exc.has_error_label("RetryableError")
overloaded = exc.has_error_label("SystemOverloadedError")
if not always_retryable and (
self._is_not_eligible_for_retry()
or (
@ -2815,8 +2815,8 @@ class _ClientConnectionRetryable(Generic[T]):
):
exc_to_check = exc.error
retryable_write_label = exc_to_check.has_error_label("RetryableWriteError")
always_retryable = exc_to_check.has_error_label("Retryable")
overloaded = exc_to_check.has_error_label("SystemOverloaded")
always_retryable = exc_to_check.has_error_label("RetryableError")
overloaded = exc_to_check.has_error_label("SystemOverloadedError")
if not self._retryable and not always_retryable:
raise
if retryable_write_label or always_retryable:

View File

@ -42,7 +42,7 @@ mock_overload_error = {
"data": {
"failCommands": ["find", "insert", "update"],
"errorCode": 462, # IngressRequestRateLimitExceeded
"errorLabels": ["Retryable"],
"errorLabels": ["RetryableError"],
},
}
@ -67,7 +67,7 @@ class TestBackpressure(AsyncIntegrationTest):
with self.assertRaises(PyMongoError) as error:
await self.db.command("find", "t")
self.assertIn("Retryable", str(error.exception))
self.assertIn("RetryableError", str(error.exception))
@async_client_context.require_failCommand_appName
async def test_retry_overload_error_find(self):
@ -86,7 +86,7 @@ class TestBackpressure(AsyncIntegrationTest):
with self.assertRaises(PyMongoError) as error:
await self.db.t.find_one()
self.assertIn("Retryable", str(error.exception))
self.assertIn("RetryableError", str(error.exception))
@async_client_context.require_failCommand_appName
async def test_retry_overload_error_insert_one(self):
@ -105,12 +105,12 @@ class TestBackpressure(AsyncIntegrationTest):
with self.assertRaises(PyMongoError) as error:
await self.db.t.find_one()
self.assertIn("Retryable", str(error.exception))
self.assertIn("RetryableError", str(error.exception))
@async_client_context.require_failCommand_appName
async def test_retry_overload_error_update_many(self):
# Even though update_many is not a retryable write operation, it will
# still be retried via the "Retryable" error label.
# still be retried via the "RetryableError" error label.
await self.db.t.insert_one({"x": 1})
# Ensure command is retried on overload error.
@ -126,7 +126,7 @@ class TestBackpressure(AsyncIntegrationTest):
with self.assertRaises(PyMongoError) as error:
await self.db.t.update_many({}, {"$set": {"x": 2}})
self.assertIn("Retryable", str(error.exception))
self.assertIn("RetryableError", str(error.exception))
@async_client_context.require_failCommand_appName
async def test_retry_overload_error_getMore(self):
@ -140,7 +140,7 @@ class TestBackpressure(AsyncIntegrationTest):
"data": {
"failCommands": ["getMore"],
"errorCode": 462, # IngressRequestRateLimitExceeded
"errorLabels": ["Retryable"],
"errorLabels": ["RetryableError"],
},
}
cursor = coll.find(batch_size=2)
@ -157,7 +157,7 @@ class TestBackpressure(AsyncIntegrationTest):
with self.assertRaises(PyMongoError) as error:
await cursor.to_list()
self.assertIn("Retryable", str(error.exception))
self.assertIn("RetryableError", str(error.exception))
@async_client_context.require_failCommand_appName
async def test_limit_retry_command(self):
@ -179,7 +179,7 @@ class TestBackpressure(AsyncIntegrationTest):
with self.assertRaises(PyMongoError) as error:
await db.command("find", "t")
self.assertIn("Retryable", str(error.exception))
self.assertIn("RetryableError", str(error.exception))
class TestRetryPolicy(AsyncPyMongoTestCase):

View File

@ -42,7 +42,7 @@ mock_overload_error = {
"data": {
"failCommands": ["find", "insert", "update"],
"errorCode": 462, # IngressRequestRateLimitExceeded
"errorLabels": ["Retryable"],
"errorLabels": ["RetryableError"],
},
}
@ -67,7 +67,7 @@ class TestBackpressure(IntegrationTest):
with self.assertRaises(PyMongoError) as error:
self.db.command("find", "t")
self.assertIn("Retryable", str(error.exception))
self.assertIn("RetryableError", str(error.exception))
@client_context.require_failCommand_appName
def test_retry_overload_error_find(self):
@ -86,7 +86,7 @@ class TestBackpressure(IntegrationTest):
with self.assertRaises(PyMongoError) as error:
self.db.t.find_one()
self.assertIn("Retryable", str(error.exception))
self.assertIn("RetryableError", str(error.exception))
@client_context.require_failCommand_appName
def test_retry_overload_error_insert_one(self):
@ -105,12 +105,12 @@ class TestBackpressure(IntegrationTest):
with self.assertRaises(PyMongoError) as error:
self.db.t.find_one()
self.assertIn("Retryable", str(error.exception))
self.assertIn("RetryableError", str(error.exception))
@client_context.require_failCommand_appName
def test_retry_overload_error_update_many(self):
# Even though update_many is not a retryable write operation, it will
# still be retried via the "Retryable" error label.
# still be retried via the "RetryableError" error label.
self.db.t.insert_one({"x": 1})
# Ensure command is retried on overload error.
@ -126,7 +126,7 @@ class TestBackpressure(IntegrationTest):
with self.assertRaises(PyMongoError) as error:
self.db.t.update_many({}, {"$set": {"x": 2}})
self.assertIn("Retryable", str(error.exception))
self.assertIn("RetryableError", str(error.exception))
@client_context.require_failCommand_appName
def test_retry_overload_error_getMore(self):
@ -140,7 +140,7 @@ class TestBackpressure(IntegrationTest):
"data": {
"failCommands": ["getMore"],
"errorCode": 462, # IngressRequestRateLimitExceeded
"errorLabels": ["Retryable"],
"errorLabels": ["RetryableError"],
},
}
cursor = coll.find(batch_size=2)
@ -157,7 +157,7 @@ class TestBackpressure(IntegrationTest):
with self.assertRaises(PyMongoError) as error:
cursor.to_list()
self.assertIn("Retryable", str(error.exception))
self.assertIn("RetryableError", str(error.exception))
@client_context.require_failCommand_appName
def test_limit_retry_command(self):
@ -179,7 +179,7 @@ class TestBackpressure(IntegrationTest):
with self.assertRaises(PyMongoError) as error:
db.command("find", "t")
self.assertIn("Retryable", str(error.exception))
self.assertIn("RetryableError", str(error.exception))
class TestRetryPolicy(PyMongoTestCase):