API: Allow retry with same idempotency token after error 500

This commit is contained in:
Raphael Michel
2021-04-12 16:30:16 +02:00
parent a93287207b
commit a96023af01
2 changed files with 5 additions and 2 deletions

View File

@@ -213,13 +213,16 @@ Please note that this also goes for most error responses. For example, if we ret
error and you retry with the same ``X-Idempotency-Key``, you will get the same error again, even if you were granted error and you retry with the same ``X-Idempotency-Key``, you will get the same error again, even if you were granted
permission in the meantime! This includes internal server errors on our side that might have been fixed in the meantime. permission in the meantime! This includes internal server errors on our side that might have been fixed in the meantime.
There are only three exceptions to the rule: There are only the following exceptions to the rule:
* Responses with status code ``409 Conflict`` are not cached. If you send the request again, it will be executed as a * Responses with status code ``409 Conflict`` are not cached. If you send the request again, it will be executed as a
new request, since these responses are intended to be retried. new request, since these responses are intended to be retried.
* Rate-limited responses with status code ``429 Too Many Requests`` are not cached and you can safely retry them. * Rate-limited responses with status code ``429 Too Many Requests`` are not cached and you can safely retry them.
* Responses with status code ``500 Internal Server Error`` are not cached and you can retry them. This is not guaranteed
to be safe in all theoretical cases, but 500 by definition is an unforseen situation and we need to have some way out.
* Responses with status code ``503 Service Unavailable`` are not cached and you can safely retry them. * Responses with status code ``503 Service Unavailable`` are not cached and you can safely retry them.
If you send a request with an ``X-Idempotency-Key`` header that we have seen before but that has not yet received a If you send a request with an ``X-Idempotency-Key`` header that we have seen before but that has not yet received a

View File

@@ -72,7 +72,7 @@ class IdempotencyMiddleware:
if created: if created:
resp = self.get_response(request) resp = self.get_response(request)
with transaction.atomic(): with transaction.atomic():
if resp.status_code in (409, 429, 503): if resp.status_code in (409, 429, 500, 503):
# This is the exception: These calls are *meant* to be retried! # This is the exception: These calls are *meant* to be retried!
call.delete() call.delete()
else: else: