Skip to content

Commit cbb90a8

Browse files
authored
fix(workflows): Rule.status derived from snooze, not Workflow.status (#112302)
Snooze status should be stored in appropriate fields; using 'status=disabled' just results in the UI showing a warning banner as if the rule is broken. Fixes ISWF-2402.
1 parent 045eb21 commit cbb90a8

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

src/sentry/api/serializers/models/rule.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,15 @@ def serialize(self, obj: Workflow, attrs, user, **kwargs) -> RuleSerializerRespo
796796
"createdBy": attrs.get("created_by", None),
797797
"environment": environment.name if environment is not None else None,
798798
"projects": [p.slug for p in attrs["projects"]],
799-
"status": "active" if obj.enabled else "disabled",
800-
"snooze": "snooze" in attrs,
799+
# Workflow.enabled is toggled by snooze-for-everyone, but "disabled" in the
800+
# UI means a broken/misconfigured rule (matching legacy Rule.status/ObjectStatus).
801+
# Snooze state is communicated via the snooze fields instead.
802+
"status": "active",
803+
"snooze": not obj.enabled,
801804
}
805+
if not obj.enabled:
806+
workflow_rule["snoozeForEveryone"] = True
807+
802808
if "last_triggered" in attrs:
803809
workflow_rule["lastTriggered"] = attrs["last_triggered"]
804810

tests/sentry/api/endpoints/test_project_rule_details.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,47 @@ def test_dual_written_rule_parity(self) -> None:
19771977
assert legacy_response.data["id"] == str(rule.id)
19781978
assert_serializer_parity(old=legacy_response.data, new=we_response.data)
19791979

1980+
def test_snoozed_rule_for_everyone_parity(self) -> None:
1981+
rule = self.create_project_rule(
1982+
project=self.project,
1983+
name="Snoozed for everyone alert",
1984+
action_match="any",
1985+
frequency=60,
1986+
condition_data=[
1987+
{
1988+
"id": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
1989+
"name": "A new issue is created",
1990+
},
1991+
],
1992+
action_data=[
1993+
{
1994+
"targetType": "IssueOwners",
1995+
"fallthroughType": "ActiveMembers",
1996+
"id": "sentry.mail.actions.NotifyEmailAction",
1997+
"targetIdentifier": "",
1998+
"name": "Send a notification to IssueOwners and if none can be found then send a notification to ActiveMembers",
1999+
}
2000+
],
2001+
)
2002+
self.snooze_rule(owner_id=self.user.id, rule=rule)
2003+
2004+
legacy_response = self.get_success_response(
2005+
self.organization.slug, self.project.slug, rule.id, status_code=200
2006+
)
2007+
with self.feature("organizations:workflow-engine-rule-serializers"):
2008+
we_response = self.get_success_response(
2009+
self.organization.slug, self.project.slug, rule.id, status_code=200
2010+
)
2011+
2012+
assert legacy_response.data["id"] == str(rule.id)
2013+
assert legacy_response.data["snooze"]
2014+
assert legacy_response.data["snoozeForEveryone"]
2015+
assert_serializer_parity(
2016+
old=legacy_response.data,
2017+
new=we_response.data,
2018+
known_differences={"snoozeCreatedBy"},
2019+
)
2020+
19802021
def test_dual_written_rule_with_filters_parity(self) -> None:
19812022
rule = self.create_project_rule(
19822023
project=self.project,

tests/sentry/api/endpoints/test_project_rules.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,3 +1673,53 @@ def test_dual_written_rule_parity(self) -> None:
16731673
assert legacy_rule["id"] == str(rule.id)
16741674

16751675
assert_serializer_parity(old=legacy_rule, new=we_rule)
1676+
1677+
def test_snoozed_rule_for_everyone_parity(self) -> None:
1678+
self.login_as(user=self.user)
1679+
rule = self.create_project_rule(
1680+
project=self.project,
1681+
name="Snoozed for everyone alert",
1682+
action_match="any",
1683+
frequency=60,
1684+
condition_data=[
1685+
{
1686+
"id": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
1687+
"name": "A new issue is created",
1688+
},
1689+
],
1690+
action_data=[
1691+
{
1692+
"targetType": "IssueOwners",
1693+
"fallthroughType": "ActiveMembers",
1694+
"id": "sentry.mail.actions.NotifyEmailAction",
1695+
"targetIdentifier": "",
1696+
"name": "Send a notification to IssueOwners and if none can be found then send a notification to ActiveMembers",
1697+
}
1698+
],
1699+
)
1700+
self.snooze_rule(owner_id=self.user.id, rule=rule)
1701+
1702+
legacy_response = self.get_success_response(
1703+
self.organization.slug,
1704+
self.project.slug,
1705+
status_code=status.HTTP_200_OK,
1706+
)
1707+
1708+
with self.feature("organizations:workflow-engine-rule-serializers"):
1709+
we_response = self.get_success_response(
1710+
self.organization.slug,
1711+
self.project.slug,
1712+
status_code=status.HTTP_200_OK,
1713+
)
1714+
1715+
assert len(legacy_response.data) == 1
1716+
assert len(we_response.data) == 1
1717+
legacy_rule = legacy_response.data[0]
1718+
we_rule = we_response.data[0]
1719+
assert legacy_rule["id"] == str(rule.id)
1720+
assert legacy_rule["snooze"]
1721+
assert_serializer_parity(
1722+
old=legacy_rule,
1723+
new=we_rule,
1724+
known_differences={"snoozeCreatedBy"},
1725+
)

0 commit comments

Comments
 (0)