Skip to content

Commit cd42690

Browse files
lobsterkatieevanh
authored andcommitted
fix(grouping): Add default value for fingerprint rule text (#81076)
In #80935, we switched from calculating fingerprinting rule text in the `expose_fingerprint_dict` helper to reading it from the fingerprint info, since as of #79231 we store it there. This works fine for new events, but this code also runs when someone opens the grouping info section of the issue details page, and if they do that on an event from before we started storing the rule text, it results in a key error. This fixes that by partially undoing the change made in #80935 - it doesn't switch back to always re-calculating the the rule text, but does fall back to doing so when it's not found in the stored data.
1 parent 2f7f010 commit cd42690

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/sentry/grouping/variants.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import TypedDict
44

5+
from sentry.grouping.fingerprinting import FingerprintRule
56
from sentry.grouping.utils import hash_from_values, is_default_fingerprint_var
67
from sentry.types.misc import KeyedList
78

@@ -147,7 +148,11 @@ def expose_fingerprint_dict(values, info):
147148

148149
matched_rule = info.get("matched_rule")
149150
if matched_rule:
150-
rv["matched_rule"] = matched_rule["text"]
151+
# TODO: Before late October 2024, we didn't store the rule text along with the matched rule,
152+
# meaning there are still events out there whose `_fingerprint_info` entry doesn't have it.
153+
# Once those events have aged out (in February or so), we can remove the default value here
154+
# and the `test_old_event_with_no_fingerprint_rule_text` test in `test_variants.py`.
155+
rv["matched_rule"] = matched_rule.get("text", FingerprintRule.from_json(matched_rule).text)
151156

152157
return rv
153158

tests/sentry/grouping/test_variants.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from sentry.eventstore.models import Event
66
from sentry.grouping.strategies.configurations import CONFIGURATIONS
7+
from sentry.grouping.variants import CustomFingerprintVariant, expose_fingerprint_dict
78
from sentry.models.project import Project
89
from sentry.projectoptions.defaults import DEFAULT_GROUPING_CONFIG
910
from sentry.testutils.pytest.fixtures import InstaSnapshotter, django_db_all
@@ -97,3 +98,22 @@ def _assert_and_snapshot_results(
9798
__file__, input_file, "test_event_hash_variant", config_name
9899
),
99100
)
101+
102+
103+
# TODO: This can be deleted after Jan 2025, when affected events have aged out
104+
def test_old_event_with_no_fingerprint_rule_text():
105+
variant = CustomFingerprintVariant(
106+
["dogs are great"],
107+
{
108+
"matched_rule": {
109+
"attributes": {},
110+
"fingerprint": ["dogs are great"],
111+
"matchers": [["message", "*dogs*"]],
112+
# newer events have a `text` entry here
113+
}
114+
},
115+
)
116+
assert expose_fingerprint_dict(variant.values, variant.info) == {
117+
"values": ["dogs are great"],
118+
"matched_rule": 'message:"*dogs*" -> "dogs are great"',
119+
}

0 commit comments

Comments
 (0)