From 54f0bb891a1367b10b52209ec9c52bb7df5c2d00 Mon Sep 17 00:00:00 2001 From: Fabian Schindler Date: Thu, 10 Jul 2025 12:06:52 +0200 Subject: [PATCH 1/3] fix(analytics): missing 'data' attribute exclusion --- src/sentry/analytics/event.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/sentry/analytics/event.py b/src/sentry/analytics/event.py index 364f4ca05e6992..cb7c83683d42b7 100644 --- a/src/sentry/analytics/event.py +++ b/src/sentry/analytics/event.py @@ -113,7 +113,13 @@ def from_instance(cls, instance: Any, **kwargs: Any) -> Self: **{ f.name: kwargs.get(f.name, getattr(instance, f.name, None)) for f in fields(cls) - if f.name not in ("type", "uuid_", "datetime_") + if f.name + not in ( + "type", + "uuid_", + "datetime_", + "data", # TODO: remove this data field once migrated + ) } ) From bd4eaf14ff03170f8ccf8294318ba1919a452353 Mon Sep 17 00:00:00 2001 From: Fabian Schindler Date: Thu, 10 Jul 2025 13:37:49 +0200 Subject: [PATCH 2/3] test(analytics): add test for new-style events .from_instance() --- tests/sentry/analytics/test_event.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/sentry/analytics/test_event.py b/tests/sentry/analytics/test_event.py index 7c197739dc3ff0..adfeb8620f47b6 100644 --- a/tests/sentry/analytics/test_event.py +++ b/tests/sentry/analytics/test_event.py @@ -53,6 +53,29 @@ def test_simple(self, mock_uuid1): "uuid": b"AAEC", } + @patch("sentry.analytics.event.uuid1") + def test_simple_from_instance(self, mock_uuid1): + mock_uuid1.return_value = self.get_mock_uuid() + + result = ExampleEvent.from_instance( + None, + id="1", # type: ignore[arg-type] + map={"key": "value"}, + optional=False, + ) + result.datetime_ = datetime(2001, 4, 18, tzinfo=timezone.utc) + + assert result.serialize() == { + "data": { + "id": 1, + "map": {"key": "value"}, + "optional": False, + }, + "type": "example", + "timestamp": 987552000, + "uuid": b"AAEC", + } + @patch("sentry.analytics.event.uuid1") def test_simple_old_style(self, mock_uuid1): mock_uuid1.return_value = self.get_mock_uuid() From 6cabd5aa6a332bf951768ccb2e60d9c78d7b3f2f Mon Sep 17 00:00:00 2001 From: Fabian Schindler Date: Thu, 10 Jul 2025 17:05:52 +0200 Subject: [PATCH 3/3] fix(analytics): fixing type check --- tests/sentry/analytics/test_event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sentry/analytics/test_event.py b/tests/sentry/analytics/test_event.py index adfeb8620f47b6..c105df72110aae 100644 --- a/tests/sentry/analytics/test_event.py +++ b/tests/sentry/analytics/test_event.py @@ -59,7 +59,7 @@ def test_simple_from_instance(self, mock_uuid1): result = ExampleEvent.from_instance( None, - id="1", # type: ignore[arg-type] + id="1", map={"key": "value"}, optional=False, )