Skip to content

Commit

Permalink
ref(rules): Handle improperly formatted rule (#70797)
Browse files Browse the repository at this point in the history
One customer has a couple improperly formatted alert rules that are
causing this error: https://sentry.sentry.io/issues/5245475486/. I've
already edited the serializer so it's not possible to get into this
state again (we don't save data with a value of "") and had support
reach out to the customer to address this, but this issue keeps
happening so we can just handle the empty string.
  • Loading branch information
ceorourke committed May 14, 2024
1 parent c7c3256 commit 0c724d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/sentry/rules/conditions/event_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def passes(self, event: GroupEvent, state: EventState) -> bool:

comparison_type = self.get_option("comparisonType", ComparisonType.COUNT)
comparison_interval_option = self.get_option("comparisonInterval", "5m")
if comparison_interval_option == "":
return False
comparison_interval = COMPARISON_INTERVALS[comparison_interval_option][1]
_, duration = self.intervals[interval]
try:
Expand Down
9 changes: 9 additions & 0 deletions tests/snuba/rules/conditions/test_event_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ def _run_test(self, minutes, data, passes, add_events=False):
self.assertDoesNotPass(rule, event, is_new=False)
self.assertDoesNotPass(environment_rule, event, is_new=False)

def test_comparison_interval_empty_string(self):
data = {
"interval": "1m",
"value": 16,
"comparisonType": "count",
"comparisonInterval": "",
}
self._run_test(data=data, minutes=1, passes=False)

def test_one_minute_with_events(self):
data = {"interval": "1m", "value": 6, "comparisonType": "count", "comparisonInterval": "5m"}
self._run_test(data=data, minutes=1, passes=True, add_events=True)
Expand Down

0 comments on commit 0c724d5

Please sign in to comment.