Skip to content

fix(workflow-engine): Handle missing ActionTarget in combined-rules serializer#119075

Closed
sentry[bot] wants to merge 11 commits into
masterfrom
seer/fix-workflow-engine-action-target-none
Closed

fix(workflow-engine): Handle missing ActionTarget in combined-rules serializer#119075
sentry[bot] wants to merge 11 commits into
masterfrom
seer/fix-workflow-engine-action-target-none

Conversation

@sentry

@sentry sentry Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

This PR addresses issue SENTRY-5QVV, where a ValueError: None is not a valid ActionTarget was occurring during the serialization of workflow engine actions.

The root cause was that some Action model records, particularly those created via certain migration paths or for specific action types (like PagerDuty/OpsGenie), did not have a target_type key in their config JSON. When the WorkflowEngineActionSerializer attempted to convert this None value to an ActionTarget enum, it resulted in a ValueError.

The fix involves:

  1. Adding a null-check in src/sentry/incidents/endpoints/serializers/workflow_engine_action.py to ensure that ActionTarget(target_type) is only called when target_type is not None. If target_type is None, the serialized targetType will also be None.
  2. Adding a logger.warning when target_type is None to provide visibility into these cases, including the action_id and action_type for debugging.

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-5QVV

Comment @sentry <feedback> on this PR to have Autofix iterate on the changes.

@sentry sentry Bot requested a review from a team as a code owner July 6, 2026 19:47
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 6, 2026
@alexsohn1126 alexsohn1126 added the Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests label Jul 6, 2026
Comment on lines +79 to 82
if target_type is not None
else None,
"targetIdentifier": get_identifier_from_action(
type_value, str(target_identifier), target_display

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Calling str(target_identifier) when target_identifier is None leads to a ValueError when int() is called on the resulting string "None" for certain action types.
Severity: HIGH

Suggested Fix

Conditionally handle the case where target_identifier is None. Before converting it to a string, check if it is None and pass None or a sensible default to get_identifier_from_action. The get_identifier_from_action function should also be updated to handle a None or default value gracefully instead of assuming a valid integer string.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/sentry/incidents/endpoints/serializers/workflow_engine_action.py#L79-L82

Potential issue: For PagerDuty or Sentry App actions, if the `target_identifier` is
missing from the action's configuration, it defaults to `None`. The code then
unconditionally converts this value to a string, resulting in `"None"`. This string is
passed to the `get_identifier_from_action` function, which attempts to cast it to an
integer using `int("None")`. This operation fails and raises a `ValueError`, causing a
server error during the serialization of the action.

Did we get this right? 👍 / 👎 to inform future reviews.

@alexsohn1126

Copy link
Copy Markdown
Member

@sentry add logging for when this happens

@sentry sentry Bot changed the title fix(workflow-engine): Handle missing ActionTarget in combined-rules serializer fix(workflow-engine): Gracefully handle missing ActionTarget in serializer Jul 6, 2026
@github-actions github-actions Bot removed the Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests label Jul 6, 2026
@alexsohn1126

Copy link
Copy Markdown
Member

@sentry actually nvm just remove the tests

Comment thread tests/sentry/incidents/serializers/test_workflow_engine_action.py Outdated
@sentry sentry Bot changed the title fix(workflow-engine): Gracefully handle missing ActionTarget in serializer fix(workflow-engine): Handle None ActionTarget in serializer Jul 6, 2026
@sentry sentry Bot changed the title fix(workflow-engine): Handle None ActionTarget in serializer fix(workflow-engine): Handle missing ActionTarget in combined-rules serializer Jul 6, 2026
@sentry sentry Bot changed the title fix(workflow-engine): Handle missing ActionTarget in combined-rules serializer fix(workflow-engine): Handle None ActionTarget in serializer Jul 7, 2026
@alexsohn1126

Copy link
Copy Markdown
Member

@sentry can you remove logging

@alexsohn1126

Copy link
Copy Markdown
Member

@sentry actually no add logging

@sentry sentry Bot changed the title fix(workflow-engine): Handle None ActionTarget in serializer fix(workflow-engine): Handle missing ActionTarget in action serializer Jul 7, 2026
@alexsohn1126

Copy link
Copy Markdown
Member

@sentry actually remove logging again

@sentry sentry Bot changed the title fix(workflow-engine): Handle missing ActionTarget in action serializer fix(workflow-engine): Handle missing ActionTarget in combined-rules serializer Jul 7, 2026
@alexsohn1126 alexsohn1126 deleted the seer/fix-workflow-engine-action-target-none branch July 7, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant