-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
fix(deletions): Prevent DB call from deleting issue #95915
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
Merged
+57
−18
Merged
Changes from all commits
Commits
Show all changes
2 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 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
from uuid import uuid4 | ||
|
||
from django.conf import settings | ||
from django.db.utils import OperationalError | ||
from django.utils import timezone | ||
|
||
from sentry.integrations.models.external_issue import ExternalIssue | ||
|
@@ -1637,26 +1638,28 @@ def test_bulk_delete_performance_issues(self): | |
self.assert_groups_are_gone(groups) | ||
|
||
@patch("sentry.api.helpers.group_index.delete.may_schedule_task_to_delete_hashes_from_seer") | ||
@patch("sentry.utils.audit.log_service.record_audit_log") | ||
def test_audit_log_even_if_exception_raised( | ||
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. The previous test does not apply anymore. |
||
self, mock_record_audit_log: Mock, mock_seer_delete: Mock | ||
): | ||
def test_do_not_mark_as_pending_deletion_if_seer_fails(self, mock_seer_delete: Mock): | ||
""" | ||
Test that audit log is created even if an exception is raised after the audit log is created. | ||
Test that the issue is not marked as pending deletion if the seer call fails. | ||
""" | ||
# Calling seer happens after creating the audit log entry | ||
mock_seer_delete.side_effect = Exception("Seer error!") | ||
group1 = self.create_group() | ||
# When trying to gather the hashes, the query could be cancelled by the user | ||
mock_seer_delete.side_effect = OperationalError( | ||
"QueryCanceled('canceling statement due to user request\n')" | ||
) | ||
event = self.store_event(data={}, project_id=self.project.id) | ||
group1 = Group.objects.get(id=event.group_id) | ||
assert GroupHash.objects.filter(group=group1).exists() | ||
|
||
self.login_as(user=self.user) | ||
url = f"{self.path}?id={group1.id}" | ||
with self.tasks(): | ||
response = self.client.delete(url, format="json") | ||
assert response.status_code == 500 | ||
assert response.data["detail"] == "Error deleting groups" | ||
|
||
self.assert_audit_log_entry([group1], mock_record_audit_log) | ||
|
||
# They have been marked as pending deletion but the exception prevented their complete deletion | ||
assert Group.objects.get(id=group1.id).status == GroupStatus.PENDING_DELETION | ||
# The group has not been marked as pending deletion | ||
assert Group.objects.get(id=group1.id).status == group1.status | ||
assert GroupHash.objects.filter(group=group1).exists() | ||
|
||
def test_new_event_for_pending_deletion_group_creates_new_group(self): | ||
"""Test that after deleting a group, new events with the same fingerprint create a new group.""" | ||
|
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.
If this call raises an exception (as it used to do), the exception will be caught by the endpoint and return a 500.
I moved this call here because I don't want the status of the group to be changed.
I have upcoming changes to make this function clearer and more robust.