Skip to content

Conversation

@ceorourke
Copy link
Member

@ceorourke ceorourke commented Nov 20, 2025

Companion PR to #103694 to migrate fallthroughType to fallthrough_type in Action.data. Other PR must be merged first.

@ceorourke ceorourke requested review from a team as code owners November 20, 2025 20:50
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 20, 2025
Comment on lines +11 to +19
def migrate_fallthrough_type(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Action = apps.get_model("workflow_engine", "Action")
for action in RangeQuerySetWrapper(Action.objects.all()):
if action.data.get("fallthroughType"):
new_data = action.data.copy()
del new_data["fallthroughType"]
new_data["fallthrough_type"] = action.data["fallthroughType"]
action.data = new_data
action.save()
Copy link

Choose a reason for hiding this comment

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

Bug: Migration renames fallthroughType to fallthrough_type, but EmailDataBlob expects fallthroughType, causing a TypeError.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The database migration renames the action.data field fallthroughType to fallthrough_type. However, the EmailDataBlob dataclass, used in EmailIssueAlertHandler.get_additional_fields(), still defines the field as fallthroughType. After the migration, when EmailDataBlob(**action.data) is called, it will receive fallthrough_type as an unexpected keyword argument, leading to a TypeError. This will cause all email-based workflow actions to crash.

💡 Suggested Fix

Update the EmailDataBlob dataclass field from fallthroughType to fallthrough_type to align with the migrated data key.

🤖 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/workflow_engine/migrations/0103_action_data_fallthrough_type.py#L11-L19

Potential issue: The database migration renames the `action.data` field
`fallthroughType` to `fallthrough_type`. However, the `EmailDataBlob` dataclass, used in
`EmailIssueAlertHandler.get_additional_fields()`, still defines the field as
`fallthroughType`. After the migration, when `EmailDataBlob(**action.data)` is called,
it will receive `fallthrough_type` as an unexpected keyword argument, leading to a
`TypeError`. This will cause all email-based workflow actions to crash.

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

migrations.RunPython(
code=migrate_fallthrough_type,
reverse_code=migrations.RunPython.noop,
hints={"tables": ["workflow_engine_workflowfirehistory"]},
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Migration hints specify wrong table name

The migration operates on the Action model but specifies workflow_engine_workflowfirehistory in the hints. This incorrect table name can cause database routing and failover issues in sharded/replicated environments. The hints should specify workflow_engine_action to match the table being modified.

Fix in Cursor Fix in Web

def migrate_fallthrough_type(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Action = apps.get_model("workflow_engine", "Action")
for action in RangeQuerySetWrapper(Action.objects.all()):
if action.data.get("fallthroughType"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Migration condition skips falsy fallthroughType values

The migration checks if action.data.get("fallthroughType"): which will silently skip any action where fallthroughType exists but is falsy (e.g., None, 0, False, empty string). This could result in data loss. Should use if "fallthroughType" in action.data: to migrate all occurrences of the field regardless of its value.

Fix in Cursor Fix in Web

@github-actions
Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/workflow_engine/migrations/0103_action_data_fallthrough_type.py

for 0103_action_data_fallthrough_type in workflow_engine

--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL

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.

2 participants