-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(ACI): Accept fallthrough type in actions #103694
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
8
commits into
master
Choose a base branch
from
ceorourke/fix-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
8 commits
Select commit
Hold shift + click to select a range
0fe98a3
fix(ACI): Accept fallthrough type in actions
ceorourke c1321fd
update a couple more places
ceorourke 729d5ca
typing + a missed spot
ceorourke 967f872
update another spot
ceorourke 9a12d13
fix tests
ceorourke f25849f
update tests
ceorourke f14233e
Fix another test
ceorourke 868d428
temporarily handle both cases, add test
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
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
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
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
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
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 |
|---|---|---|
|
|
@@ -10,17 +10,20 @@ | |
| from sentry.grouping.grouptype import ErrorGroupType | ||
| from sentry.incidents.grouptype import MetricIssue | ||
| from sentry.notifications.models.notificationaction import ActionTarget | ||
| from sentry.notifications.types import FallthroughChoiceType | ||
| from sentry.testutils.asserts import assert_org_audit_log_exists | ||
| from sentry.testutils.cases import APITestCase | ||
| from sentry.testutils.outbox import outbox_runner | ||
| from sentry.testutils.silo import region_silo_test | ||
| from sentry.workflow_engine.models import ( | ||
| Action, | ||
| DataConditionGroupAction, | ||
| DetectorWorkflow, | ||
| Workflow, | ||
| WorkflowDataConditionGroup, | ||
| WorkflowFireHistory, | ||
| ) | ||
| from sentry.workflow_engine.models.data_condition import Condition | ||
| from tests.sentry.workflow_engine.test_base import MockActionValidatorTranslator | ||
|
|
||
|
|
||
|
|
@@ -394,6 +397,13 @@ def setUp(self) -> None: | |
| role="member", | ||
| organization=self.organization, | ||
| ) | ||
| self.basic_condition = [ | ||
| { | ||
| "type": Condition.EQUAL.value, | ||
| "comparison": 1, | ||
| "conditionResult": True, | ||
| } | ||
| ] | ||
|
|
||
| @mock.patch("sentry.workflow_engine.endpoints.validators.base.workflow.create_audit_entry") | ||
| def test_create_workflow__basic(self, mock_audit: mock.MagicMock) -> None: | ||
|
|
@@ -428,13 +438,7 @@ def test_create_workflow__with_config(self) -> None: | |
| def test_create_workflow__with_triggers(self) -> None: | ||
| self.valid_workflow["triggers"] = { | ||
| "logicType": "any", | ||
| "conditions": [ | ||
| { | ||
| "type": "eq", | ||
| "comparison": 1, | ||
| "conditionResult": True, | ||
| } | ||
| ], | ||
| "conditions": self.basic_condition, | ||
| } | ||
|
|
||
| response = self.get_success_response( | ||
|
|
@@ -457,13 +461,7 @@ def test_create_workflow__with_actions(self, mock_action_validator: mock.MagicMo | |
| self.valid_workflow["actionFilters"] = [ | ||
| { | ||
| "logicType": "any", | ||
| "conditions": [ | ||
| { | ||
| "type": "eq", | ||
| "comparison": 1, | ||
| "conditionResult": True, | ||
| } | ||
| ], | ||
| "conditions": self.basic_condition, | ||
| "actions": [ | ||
| { | ||
| "type": Action.Type.SLACK, | ||
|
|
@@ -492,6 +490,55 @@ def test_create_workflow__with_actions(self, mock_action_validator: mock.MagicMo | |
| "actionFilters", [] | ||
| )[0].get("id") | ||
|
|
||
| @mock.patch( | ||
| "sentry.notifications.notification_action.registry.action_validator_registry.get", | ||
| return_value=MockActionValidatorTranslator, | ||
| ) | ||
| def test_create_workflow__with_fallthrough_type_action( | ||
|
Contributor
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. thank youuuu!! |
||
| self, mock_action_validator: mock.MagicMock | ||
| ) -> None: | ||
| self.valid_workflow["actionFilters"] = [ | ||
| { | ||
| "logicType": "any", | ||
| "conditions": self.basic_condition, | ||
| "actions": [ | ||
| { | ||
| "type": Action.Type.EMAIL, | ||
| "config": { | ||
| "targetType": "issue_owners", | ||
| }, | ||
| "data": {"fallthroughType": "ActiveMembers"}, | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| ], | ||
| } | ||
| ] | ||
|
|
||
| response = self.get_success_response( | ||
| self.organization.slug, | ||
| raw_data=self.valid_workflow, | ||
| ) | ||
|
|
||
| assert response.status_code == 201 | ||
| new_workflow = Workflow.objects.get(id=response.data["id"]) | ||
| new_action_filters = WorkflowDataConditionGroup.objects.filter(workflow=new_workflow) | ||
| assert len(new_action_filters) == len(response.data.get("actionFilters", [])) | ||
| dcga = DataConditionGroupAction.objects.filter( | ||
| condition_group=new_action_filters[0].condition_group | ||
| ).first() | ||
| assert dcga | ||
| assert str(new_action_filters[0].condition_group.id) == response.data.get( | ||
| "actionFilters", [] | ||
| )[0].get("id") | ||
| assert ( | ||
| response.data.get("actionFilters")[0] | ||
| .get("actions")[0] | ||
| .get("data") | ||
| .get("fallthrough_type") | ||
| == FallthroughChoiceType.ACTIVE_MEMBERS.value | ||
| ) | ||
| assert dcga.action.type == Action.Type.EMAIL | ||
| assert dcga.action.data == {"fallthrough_type": "ActiveMembers"} | ||
|
|
||
| def test_create_invalid_workflow(self) -> None: | ||
| self.valid_workflow["name"] = "" | ||
| response = self.get_response( | ||
|
|
||
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
Oops, something went wrong.
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: CamelCase key silently overwrites snake_case key
When both
fallthroughTypeandfallthrough_typekeys exist inaction.data, the camelCase version silently overwrites the snake_case version. The schema allows both keys simultaneously without mutual exclusivity constraints, and the conversion logic on line 58 unconditionally overwritesfallthrough_typewith the value fromfallthroughType, potentially discarding the user's intended value.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.
that is the point