Skip to content

Commit 083a28a

Browse files
authored
fix(alerts): Handle None when parsing event exceptions (#70173)
Fixes SENTRY-Y88
1 parent a04effd commit 083a28a

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/sentry/rules/conditions/event_attribute.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ def _get_attribute_values(self, event: GroupEvent, attr: str) -> Sequence[object
119119
if path[1] not in ("type", "value"):
120120
return []
121121

122-
return [getattr(e, path[1]) for e in event.interfaces["exception"].values]
122+
return [
123+
getattr(e, path[1]) for e in event.interfaces["exception"].values if e is not None
124+
]
123125

124126
elif path[0] == "error":
125127
# TODO: add support for error.main_thread

tests/sentry/rules/conditions/test_event_attribute.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,3 +768,32 @@ def test_unreal_crash_type(self):
768768
data={"match": MatchType.EQUAL, "attribute": "unreal.crash_type", "value": "NoCrash"}
769769
)
770770
self.assertDoesNotPass(rule, event)
771+
772+
def test_does_not_error_with_none(self):
773+
exception = {
774+
"values": [
775+
None,
776+
{
777+
"type": "SyntaxError",
778+
"value": "hello world",
779+
"stacktrace": {
780+
"frames": [
781+
{
782+
"filename": "example.php",
783+
"module": "example",
784+
"context_line": 'echo "hello";',
785+
"abs_path": "path/to/example.php",
786+
}
787+
]
788+
},
789+
"thread_id": 1,
790+
},
791+
]
792+
}
793+
794+
event = self.get_event(exception=exception)
795+
796+
rule = self.get_rule(
797+
data={"match": MatchType.EQUAL, "attribute": "exception.type", "value": "SyntaxError"}
798+
)
799+
self.assertPasses(rule, event)

0 commit comments

Comments
 (0)