-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(workflow-engine): Prevent ValueError for missing ActionTarget in serializer #119119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8b67358
f719f7c
f3b7c1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import logging | ||
| from collections.abc import Mapping | ||
| from typing import Any, Sequence | ||
|
|
||
|
|
@@ -16,8 +17,10 @@ | |
| ) | ||
| from sentry.users.models.user import User | ||
| from sentry.users.services.user.model import RpcUser | ||
| from sentry.workflow_engine.models import Action, ActionAlertRuleTriggerAction | ||
|
Check warning on line 20 in src/sentry/incidents/endpoints/serializers/workflow_engine_action.py
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class WorkflowEngineActionSerializer(Serializer[dict[str, Any]]): | ||
| def get_attrs( | ||
|
|
@@ -57,10 +60,16 @@ | |
| type_value: int | None = ActionService.get_value(obj.type) | ||
| target = attrs.get("target") | ||
|
|
||
| target_type: int = obj.config.get("target_type") | ||
| target_type: int | None = obj.config.get("target_type") | ||
| target_identifier: str | None = obj.config.get("target_identifier") | ||
| target_display: str | None = obj.config.get("target_display") | ||
|
|
||
| if target_type is None: | ||
| logger.warning( | ||
| "workflow_engine_action.missing_target_type", | ||
| extra={"action_id": obj.id, "action_type": obj.type}, | ||
| ) | ||
|
|
||
| sentry_app_id = None | ||
| sentry_app_config = None | ||
| if obj.type == Action.Type.SENTRY_APP.value: | ||
|
|
@@ -75,7 +84,9 @@ | |
| ), | ||
| "alertRuleTriggerId": str(alert_rule_trigger_id), | ||
| "type": obj.type, | ||
| "targetType": ACTION_TARGET_TYPE_TO_STRING[ActionTarget(target_type)], | ||
| "targetType": ACTION_TARGET_TYPE_TO_STRING[ActionTarget(target_type)] | ||
| if target_type is not None | ||
| else None, | ||
| "targetIdentifier": get_identifier_from_action( | ||
| type_value, str(target_identifier), target_display | ||
| ), | ||
|
Comment on lines
+88
to
92
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: If Suggested FixAdd a check to ensure Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The serializer can crash with a
ValueErrorwhen a PagerDuty or Sentry App action is missing atarget_identifier, as it attempts to runint("None").Severity: HIGH
Suggested Fix
Before calling
get_identifier_from_action, check iftarget_identifierisNone. If it is, handle it gracefully, perhaps by returningNoneor a default value, to prevent thestr()and subsequentint()conversion from crashing when the action type is PagerDuty or Sentry App.Prompt for AI Agent