fix(workflow_engine): Ignore Workflow.DoesNotExist in trigger_action task#114385
Merged
fix(workflow_engine): Ignore Workflow.DoesNotExist in trigger_action task#114385
Conversation
kcons
approved these changes
Apr 29, 2026
cleptric
pushed a commit
that referenced
this pull request
May 5, 2026
…task (#114385) <!-- Describe your PR here. --> This PR addresses the `Workflow.DoesNotExist` error occurring in the `sentry.workflow_engine.tasks.trigger_action` task. **Problem:** The `trigger_action` task, responsible for processing workflow actions, was failing with `Workflow.DoesNotExist` when attempting to fetch a `Workflow` object by its ID. This happens due to a race condition: a workflow might be soft-deleted (i.e., its status set to `PENDING_DELETION` or `DELETION_IN_PROGRESS`) between the time the `trigger_action` task is enqueued and when it actually executes. The default `Workflow.objects` manager's `get_queryset()` method explicitly excludes workflows with these deletion statuses. Consequently, if a workflow is soft-deleted, `Workflow.objects.get(id=workflow_id)` will raise `DoesNotExist`. **Why it's an issue:** The `trigger_action` task's `@retry` decorator did not include `Workflow.DoesNotExist` in its `ignore` list. This meant that instead of silently discarding the task (as is done for `Project.DoesNotExist` in similar scenarios where the underlying resource is legitimately gone), the error was being captured by Sentry, leading to unnecessary noise and reported issues. **Fix:** Added `Workflow.DoesNotExist` to the `ignore` list within the `@retry` decorator for the `trigger_action` task in `src/sentry/workflow_engine/tasks/actions.py`. This ensures that if a workflow no longer exists (because it has been soft-deleted), the task will be silently discarded without generating an error, aligning with the expected behavior for transient resource unavailability or deletion. <!-- Sentry employees and contractors can delete or ignore the following. --> ### Legal Boilerplate Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. Fixes SENTRY-5JNC Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com>
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.
This PR addresses the
Workflow.DoesNotExisterror occurring in thesentry.workflow_engine.tasks.trigger_actiontask.Problem:
The
trigger_actiontask, responsible for processing workflow actions, was failing withWorkflow.DoesNotExistwhen attempting to fetch aWorkflowobject by its ID. This happens due to a race condition: a workflow might be soft-deleted (i.e., its status set toPENDING_DELETIONorDELETION_IN_PROGRESS) between the time thetrigger_actiontask is enqueued and when it actually executes.The default
Workflow.objectsmanager'sget_queryset()method explicitly excludes workflows with these deletion statuses. Consequently, if a workflow is soft-deleted,Workflow.objects.get(id=workflow_id)will raiseDoesNotExist.Why it's an issue:
The
trigger_actiontask's@retrydecorator did not includeWorkflow.DoesNotExistin itsignorelist. This meant that instead of silently discarding the task (as is done forProject.DoesNotExistin similar scenarios where the underlying resource is legitimately gone), the error was being captured by Sentry, leading to unnecessary noise and reported issues.Fix:
Added
Workflow.DoesNotExistto theignorelist within the@retrydecorator for thetrigger_actiontask insrc/sentry/workflow_engine/tasks/actions.py. This ensures that if a workflow no longer exists (because it has been soft-deleted), the task will be silently discarded without generating an error, aligning with the expected behavior for transient resource unavailability or deletion.Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
Fixes SENTRY-5JNC