Repository navigation
fix(api): return a JSON status when a polled Celery task is revoked - #4023
Open
polylane[bot] wants to merge 1 commit into
Open
polylane[bot] wants to merge 1 commit into
polylane[bot] wants to merge 1 commit into
Conversation
Co-authored-by: polylane[bot] <277585245+polylane[bot]@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Polling the status of a background task returned HTTP 500 when the task had already expired and Celery had revoked it, because the handler tried to encode Celery's revocation error as JSON. The Auto-Linker that polls this endpoint saw the request fail instead of a terminal state. A revoked task now returns a normal JSON status. Celery stores a TaskRevokedError instance in a revoked task's result, and the endpoint copied it into the response before checking the state, so json.dumps raised. The change emits progress meta only when it is a dict and reports REVOKED as a terminal state.
Production impact at
ef3cff9: Revoked-task path returns JSON; production behavior does not regressFix walkthrough
Watch the fix explained (1:28). Recorded for commit
ef3cff9a61db5f09253de831a7f7031f657c555d.Full analysis
Detection evidence
Affected:
int_1d11030e4001koijtk9pub43Out of scope
static/js/linker.v3/main.jsstill does not treat REVOKED as terminal and exhausts its retries as before. Not changed here.Production impact
The change only replaces an unhandled 500 on an error path with a JSON response and narrows when
metais emitted. The SUCCESS and FAILURE responses are identical, and no new dependency, query, or load is added. The web service serves the affected route at steady traffic and has no other caller of the changed function.Affected resources
web-productionObservability
trace.django.request.errors{service:web,resource_name:*async*}.as_count(): the HTTP 500 count for the status route; it should fall to zero for revoked tasks after deploy.async_task_status_api:revoked(new structured log): one entry per revoked task served, at info level.async_task_status_api:failedandasync_task_status_api:pending: unchanged and still describe the other states.Polylane assessed this pull request at
ef3cff9.Causal chain
if result.info is not None and state not in ("SUCCESS", "FAILURE"): payload["meta"] = result.info, then a fall-through returning jsonResponse(payload, status=202) for REVOKED.info = result, and failed()/successful() are true only for FAILURE/SUCCESS.2 files changed (+108/-2)
sefaria/tests/async_task_status_test.py: added, +95/-0sefaria/views.py: modified, +13/-2Generated by Polylane. You can ask follow-ups by mentioning @polylane in a comment. If you close this pull request without merging, add a comment that says why. Polylane reads it to make its next fixes better.