|
| 1 | +from typing import Any |
| 2 | + |
| 3 | +from sentry.eventstore.models import Event |
| 4 | +from sentry.testutils.cases import TestCase |
| 5 | + |
| 6 | + |
| 7 | +class ChainedExceptionTest(TestCase): |
| 8 | + def test_ignores_mechanism_in_python_sdk_version_3_chained_exception_events(self): |
| 9 | + # First, get hashes for an event with no `mechanism` data |
| 10 | + event_data: dict[str, Any] = { |
| 11 | + "platform": "python", |
| 12 | + "sdk": {"name": "python", "version": "3.1"}, |
| 13 | + "exception": { |
| 14 | + "values": [ |
| 15 | + {"type": "FetchError", "value": "Charlie didn't bring the ball back"}, |
| 16 | + {"type": "ShoeError", "value": "Oh, no! Charlie ate the flip-flops!"}, |
| 17 | + {"type": "AggregateException", "value": "She's a very good dog, but..."}, |
| 18 | + ] |
| 19 | + }, |
| 20 | + } |
| 21 | + |
| 22 | + no_mechanism_hashes = Event( |
| 23 | + event_id="1121123104150908", |
| 24 | + project_id=self.project.id, |
| 25 | + data=event_data, |
| 26 | + ).get_hashes() |
| 27 | + |
| 28 | + # Now add in `mechanism` data, and we'll see that the hash doesn't change |
| 29 | + event_data["exception"]["values"][0]["mechanism"] = { |
| 30 | + "type": "chained", |
| 31 | + "handled": True, |
| 32 | + "source": "InnerExceptions[1]", |
| 33 | + "exception_id": 2, |
| 34 | + "parent_id": 0, |
| 35 | + } |
| 36 | + event_data["exception"]["values"][1]["mechanism"] = { |
| 37 | + "type": "chained", |
| 38 | + "handled": True, |
| 39 | + "source": "InnerExceptions[0]", |
| 40 | + "exception_id": 1, |
| 41 | + "parent_id": 0, |
| 42 | + } |
| 43 | + event_data["exception"]["values"][2]["mechanism"] = { |
| 44 | + "type": "AppDomain.UnhandledException", |
| 45 | + "handled": False, |
| 46 | + "is_exception_group": True, |
| 47 | + "exception_id": 0, |
| 48 | + } |
| 49 | + |
| 50 | + with_mechanism_hashes = Event( |
| 51 | + event_id="1231112109080415", |
| 52 | + project_id=self.project.id, |
| 53 | + data=event_data, |
| 54 | + ).get_hashes() |
| 55 | + |
| 56 | + assert no_mechanism_hashes == with_mechanism_hashes |
| 57 | + |
| 58 | + # Just to prove that were it not for the hack, the grouping *would* change with the addition |
| 59 | + # of mechanism data, we switch the platform |
| 60 | + event_data["platform"] = "javascript" |
| 61 | + |
| 62 | + js_with_mechanism_hashes = Event( |
| 63 | + event_id="1121201212312012", |
| 64 | + project_id=self.project.id, |
| 65 | + data=event_data, |
| 66 | + ).get_hashes() |
| 67 | + |
| 68 | + assert js_with_mechanism_hashes != no_mechanism_hashes |
0 commit comments