-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(ACI): Migrate fallthroughType to fallthrough_type #103764
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
Open
ceorourke
wants to merge
5
commits into
master
Choose a base branch
from
ceorourke/migrate-action-fallthrough-type
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1575750
fix(ACI): Migrate fallthroughType to fallthrough_type
ceorourke 67d41ba
rebase
ceorourke 831f987
make post deployment
ceorourke 9202d69
update test, update how we check for fallthrough type
ceorourke ecc1041
update hint to use correct table
ceorourke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
src/sentry/workflow_engine/migrations/0104_action_data_fallthrough_type.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Generated by Django 5.2.8 on 2025-11-24 19:57 | ||
|
|
||
| from django.db import migrations | ||
| from django.db.backends.base.schema import BaseDatabaseSchemaEditor | ||
| from django.db.migrations.state import StateApps | ||
|
|
||
| from sentry.new_migrations.migrations import CheckedMigration | ||
| from sentry.utils.query import RangeQuerySetWrapper | ||
|
|
||
|
|
||
| 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 "fallthroughType" in action.data: | ||
| new_data = action.data.copy() | ||
| del new_data["fallthroughType"] | ||
| new_data["fallthrough_type"] = action.data["fallthroughType"] | ||
| action.data = new_data | ||
| action.save() | ||
|
|
||
|
|
||
| class Migration(CheckedMigration): | ||
| # This flag is used to mark that a migration shouldn't be automatically run in production. | ||
| # This should only be used for operations where it's safe to run the migration after your | ||
| # code has deployed. So this should not be used for most operations that alter the schema | ||
| # of a table. | ||
| # Here are some things that make sense to mark as post deployment: | ||
| # - Large data migrations. Typically we want these to be run manually so that they can be | ||
| # monitored and not block the deploy for a long period of time while they run. | ||
| # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to | ||
| # run this outside deployments so that we don't block them. Note that while adding an index | ||
| # is a schema change, it's completely safe to run the operation after the code has deployed. | ||
| # Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment | ||
|
|
||
| is_post_deployment = True | ||
|
|
||
| dependencies = [ | ||
| ("workflow_engine", "0103_add_unique_constraint"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython( | ||
| code=migrate_fallthrough_type, | ||
| reverse_code=migrations.RunPython.noop, | ||
| hints={"tables": ["workflow_engine_action"]}, | ||
| ), | ||
| ] | ||
40 changes: 40 additions & 0 deletions
40
tests/sentry/workflow_engine/migrations/test_0104_action_data_fallthrough_type.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| from sentry.notifications.models.notificationaction import ActionTarget | ||
| from sentry.notifications.types import FallthroughChoiceType | ||
| from sentry.testutils.cases import TestMigrations | ||
| from sentry.workflow_engine.models import Action | ||
|
|
||
|
|
||
| class TestActionDataFallthroughType(TestMigrations): | ||
| migrate_from = "0103_add_unique_constraint" | ||
| migrate_to = "0104_action_data_fallthrough_type" | ||
| app = "workflow_engine" | ||
|
|
||
| def setup_initial_state(self) -> None: | ||
| self.org = self.create_organization(name="test-org") | ||
| self.project = self.create_project(organization=self.org) | ||
|
|
||
| self.action = Action.objects.create( | ||
| type="email", | ||
| data={"fallthroughType": FallthroughChoiceType.ACTIVE_MEMBERS}, | ||
| config={ | ||
| "target_type": ActionTarget.ISSUE_OWNERS, | ||
| "target_identifier": None, | ||
| }, | ||
| ) | ||
| self.action_no_fallthrough = Action.objects.create( | ||
| type="email", | ||
| data={}, | ||
| config={ | ||
| "target_type": ActionTarget.USER, | ||
| "target_identifier": str(self.user.id), | ||
| }, | ||
| ) | ||
|
|
||
| def test_migration(self) -> None: | ||
| fallthrough_action = Action.objects.filter( | ||
| data={"fallthrough_type": FallthroughChoiceType.ACTIVE_MEMBERS} | ||
| ) | ||
| assert len(fallthrough_action) == 1 | ||
|
|
||
| no_fallthrough_action = Action.objects.filter(data={}) | ||
| assert len(no_fallthrough_action) == 1 |
Oops, something went wrong.
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.
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
EmailDataBlobdataclass instantiation will fail after migration due to unexpected keyword arguments fromaction_data.Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
After migration
0104_action_data_fallthrough_type.pyruns, theEmailIssueAlertHandler.get_additional_fields()method will attempt to instantiateEmailDataBlobusingEmailDataBlob(**action_data). Theaction_datadictionary will contain keys such astargetType,targetIdentifier,uuid, andidin addition tofallthrough_type. Since theEmailDataBlobdataclass only definesfallthrough_type, passing these unexpected keyword arguments will raise aTypeError(e.g.,__init__() got an unexpected keyword argument 'targetType'). This will lead to a server crash whenever an email action withtarget_type == ActionTarget.ISSUE_OWNERSis processed.💡 Suggested Fix
Modify the
EmailIssueAlertHandler.get_additional_fields()method to filteraction_databefore instantiatingEmailDataBlob, ensuring onlyfallthrough_typeis passed. Alternatively, update theEmailDataBlobdataclass to include all relevant fields fromaction_data.🤖 Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID:
3286846There 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.
This seems out of scope and kinda unrelated - I updated
EmailDataBlobin the other PR to usefallthrough_typeinstead offallthroughTypehttps://github.com/getsentry/sentry/blob/master/src/sentry/workflow_engine/typings/notification_action.py#L737-L743, if it's missing other kwargs that's a different problem.