-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(analytics): log an error when an Event class was instantiated that lacks the eventclass decorator #98922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(analytics): log an error when an Event class was instantiated that lacks the eventclass decorator #98922
Conversation
…at lacks the eventclass decorator
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
src/sentry/analytics/event.py
Outdated
| current_annotations = getattr(cls, "__annotations__", {}) | ||
|
|
||
| # Filter out ClassVar annotations as they're not instance fields | ||
| current_fields: set[str] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the fields are not annotated?
Is there a way to force annotations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the fields are not annotated?
Then they don't show up here. Not sure how and why that would happen, though.
Is there a way to force annotations?
No, I don't think so
| class ExampleEventWithoutEventclass(ExampleEvent): | ||
| new_field: str = "test" | ||
|
|
||
| with pytest.raises(TypeError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we testing for this?
The code doesn't seem to introduce the throwing of an error, why is this triggered in tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually does, because we are using a subclass of a dataclass without adding the dataclass or in our cases eventclass decorator. This is why there is an outdated constructor with the new_field element missing.
Closes https://linear.app/getsentry/issue/TET-808/analytics-investigate-whether-and-how-to-force-use-of-eventclass