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 + ) } ) diff --git a/tests/sentry/analytics/test_event.py b/tests/sentry/analytics/test_event.py index 7c197739dc3ff0..c105df72110aae 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", + 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()