-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
feat(workflow_engine): Schedule Deletion for Workflow #85665
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
This file contains 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 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 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,29 @@ | ||
from sentry.deletions.base import BaseRelation, ModelDeletionTask, ModelRelation | ||
from sentry.workflow_engine.models import Action, DataConditionGroup, Workflow | ||
|
||
|
||
class WorkflowDeletionTask(ModelDeletionTask[Workflow]): | ||
def get_child_relations(self, instance: Workflow) -> list[BaseRelation]: | ||
model_relations: list[BaseRelation] = [] | ||
|
||
action_filter_ids = DataConditionGroup.objects.filter( | ||
workflowdataconditiongroup__workflow_id=instance.id | ||
).values_list("id", flat=True) | ||
|
||
if action_filter_ids: | ||
# Action Filters | ||
model_relations.append(ModelRelation(DataConditionGroup, {"id__in": action_filter_ids})) | ||
|
||
# Actions - This is required until the notification center maintains these actions | ||
model_relations.append( | ||
ModelRelation( | ||
Action, {"dataconditiongroupaction__condition_group__in": action_filter_ids} | ||
) | ||
) | ||
|
||
if instance.when_condition_group: | ||
model_relations.append( | ||
ModelRelation(DataConditionGroup, {"id": instance.when_condition_group.id}) | ||
) | ||
|
||
return model_relations |
This file contains 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,75 @@ | ||
import pytest | ||
|
||
from sentry.deletions.tasks.scheduled import run_scheduled_deletions | ||
from sentry.testutils.factories import Factories | ||
from sentry.testutils.helpers import TaskRunner | ||
from sentry.testutils.hybrid_cloud import HybridCloudTestMixin | ||
|
||
# from tests.sentry.workflow_engine.test_base import BaseWorkflowTest | ||
from sentry.testutils.pytest.fixtures import django_db_all | ||
|
||
|
||
@django_db_all | ||
class TestDeleteWorkflow(HybridCloudTestMixin): | ||
def tasks(self): | ||
return TaskRunner() | ||
|
||
@pytest.fixture(autouse=True) | ||
def setUp(self): | ||
self.organization = Factories.create_organization() | ||
self.project = Factories.create_project(organization=self.organization) | ||
|
||
self.workflow = Factories.create_workflow() | ||
self.workflow_trigger = Factories.create_data_condition_group( | ||
organization=self.organization | ||
) | ||
self.workflow.when_condition_group = self.workflow_trigger | ||
self.workflow.save() | ||
|
||
self.action_filter = Factories.create_data_condition_group(organization=self.organization) | ||
self.action = Factories.create_action() | ||
self.action_and_filter = Factories.create_data_condition_group_action( | ||
condition_group=self.action_filter, | ||
action=self.action, | ||
) | ||
|
||
self.workflow_actions = Factories.create_workflow_data_condition_group( | ||
workflow=self.workflow, | ||
condition_group=self.action_filter, | ||
) | ||
|
||
self.trigger_condition = Factories.create_data_condition( | ||
condition_group=self.workflow_trigger, | ||
comparison=1, | ||
condition_result=True, | ||
) | ||
|
||
self.action_condition = Factories.create_data_condition( | ||
condition_group=self.action_filter, | ||
comparison=1, | ||
condition_result=True, | ||
) | ||
|
||
@pytest.mark.parametrize( | ||
"instance_attr", | ||
[ | ||
"workflow", | ||
"workflow_trigger", | ||
"action_filter", | ||
"action_and_filter", | ||
"workflow_actions", | ||
"trigger_condition", | ||
"action_condition", | ||
], | ||
) | ||
def test_delete_workflow(self, instance_attr): | ||
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. should we have a test with multiple actions? 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. 👍 also, woo! this comment made me realize i missed |
||
instance = getattr(self, instance_attr) | ||
instance_id = instance.id | ||
cls = instance.__class__ | ||
|
||
self.ScheduledDeletion.schedule(instance=self.workflow, days=0) | ||
|
||
with self.tasks(): | ||
run_scheduled_deletions() | ||
|
||
assert not cls.objects.filter(id=instance_id).exists() |
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.
guessing you meant to remove this