Skip to content

Commit e2f36e2

Browse files
mifu67kcons
andauthored
fix(aci): ignore groups that shouldn't be manually resolved (#102729)
Metric issues should not be manually resolved. We prevent this on the frontend, but not in API calls. Add logic to ignore these groups on the backend. [Fixes SENTRY-5BXQ](https://sentry.sentry.io/issues/6995480460/) --------- Co-authored-by: Kyle Consalus <kyle.consalus@sentry.io>
1 parent 47dd7cf commit e2f36e2

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

src/sentry/api/helpers/group_index/update.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from sentry.db.models.query import create_or_update
2626
from sentry.hybridcloud.rpc import coerce_id_from
2727
from sentry.integrations.tasks.kick_off_status_syncs import kick_off_status_syncs
28-
from sentry.issues.grouptype import GroupCategory, get_group_type_by_type_id
28+
from sentry.issues.grouptype import GroupCategory
2929
from sentry.issues.ignored import handle_archived_until_escalating, handle_ignored
3030
from sentry.issues.merge import MergedGroup, handle_merge
3131
from sentry.issues.priority import update_priority
@@ -206,12 +206,9 @@ def update_groups(
206206
status = result.get("status")
207207
res_type = None
208208
if "priority" in result:
209-
if any(
210-
not get_group_type_by_type_id(group.type).enable_user_priority_changes
211-
for group in groups
212-
):
209+
if any(not group.issue_type.enable_user_status_and_priority_changes for group in groups):
213210
return Response(
214-
{"detail": "Cannot manually set priority of a metric issue."},
211+
{"detail": "Cannot manually set priority of one or more issues."},
215212
status=HTTPStatus.BAD_REQUEST,
216213
)
217214

@@ -222,6 +219,12 @@ def update_groups(
222219
project_lookup=project_lookup,
223220
)
224221
if status in ("resolved", "resolvedInNextRelease"):
222+
if any(not group.issue_type.enable_user_status_and_priority_changes for group in groups):
223+
return Response(
224+
{"detail": "Cannot manually resolve one or more issues."},
225+
status=HTTPStatus.BAD_REQUEST,
226+
)
227+
225228
try:
226229
result, res_type = handle_resolve_in_release(
227230
status,

src/sentry/incidents/grouptype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class MetricIssue(GroupType):
333333
enable_escalation_detection = False
334334
enable_status_change_workflow_notifications = False
335335
enable_workflow_notifications = False
336-
enable_user_priority_changes = False
336+
enable_user_status_and_priority_changes = False
337337
detector_settings = DetectorSettings(
338338
handler=MetricIssueDetectorHandler,
339339
validator=MetricIssueDetectorValidator,

src/sentry/issues/grouptype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class GroupType:
219219
enable_workflow_notifications = True
220220

221221
# Controls whether users are able to manually update the group's priority.
222-
enable_user_priority_changes = True
222+
enable_user_status_and_priority_changes = True
223223

224224
# Controls whether Seer automation is always triggered for this group type.
225225
always_trigger_seer_automation = False

src/sentry/workflow_engine/typings/grouptype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ class IssueStreamGroupType(GroupType):
1717
enable_escalation_detection = False
1818
enable_status_change_workflow_notifications = False
1919
enable_workflow_notifications = False
20-
enable_user_priority_changes = False
20+
enable_user_status_and_priority_changes = False

tests/sentry/issues/endpoints/test_organization_group_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4230,7 +4230,7 @@ def test_cannot_update_metric_issue_priority(self) -> None:
42304230
qs_params={"id": [group.id]}, priority=PriorityLevel.MEDIUM.to_str()
42314231
)
42324232
assert response.status_code == 400
4233-
assert response.data["detail"] == "Cannot manually set priority of a metric issue."
4233+
assert response.data["detail"] == "Cannot manually set priority of one or more issues."
42344234

42354235

42364236
class GroupDeleteTest(APITestCase, SnubaTestCase):

tests/snuba/api/endpoints/test_project_group_index.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from django.conf import settings
1313
from django.utils import timezone
1414

15+
from sentry.incidents.grouptype import MetricIssue
1516
from sentry.integrations.models.external_issue import ExternalIssue
1617
from sentry.integrations.models.organization_integration import OrganizationIntegration
1718
from sentry.issues.grouptype import PerformanceSlowDBQueryGroupType
@@ -486,6 +487,20 @@ def test_bulk_resolve(self) -> None:
486487

487488
assert len(response.data) == 0
488489

490+
def test_exclude_metric_issue(self) -> None:
491+
self.login_as(user=self.user)
492+
493+
self.create_group()
494+
self.create_group(type=MetricIssue.type_id)
495+
496+
response = self.client.put(
497+
f"{self.path}?status=unresolved&query=is:unresolved",
498+
data={"status": "resolved"},
499+
format="json",
500+
)
501+
assert response.status_code == 400, response.data
502+
assert response.data["detail"] == "Cannot manually resolve one or more issues."
503+
489504
@patch("sentry.integrations.example.integration.ExampleIntegration.sync_status_outbound")
490505
def test_resolve_with_integration(self, mock_sync_status_outbound: MagicMock) -> None:
491506
self.login_as(user=self.user)

0 commit comments

Comments
 (0)