Skip to content

chore(notif-platform): Adds basic skeleton for notification service, fixes typing issues surrounding provider generics #93880

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GabeVillalobos
Copy link
Member

WIP: Adds a shell for notification service, modifies typing for providers to account for generics, and type ambiguity when using them.

…fixes typing issues surrounding provider generics
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 18, 2025
Comment on lines +40 to +47
def _send_notification(
cls,
*,
notification_content: EmailRenderable,
notification_type: NotificationType,
target: NotificationTarget,
thread_id: str | None = None,
) -> None: ...
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add doc comments, but this should handle actually sending the notification to the provider.

Comment on lines +8 to +26
@staticmethod
def notify_target(
target: NotificationTarget,
template: Any,
data: Any,
thread_id: str | None = None,
) -> None:
provider = provider_registry.get(target.provider_key)
provider.dispatch_notification(
target=target, template=template, data=data, thread_id=thread_id
)

@staticmethod
def notify_many_targets(
targets: list[NotificationTarget],
template: Any,
data: Any,
thread_id: str | None = None,
) -> None: ...
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should queue tasks per target, but this showcases how to address the typing issues we saw before.

Comment on lines +35 to +51
def dispatch_notification(
cls,
*,
target: NotificationTarget,
template: Any,
data: Any,
thread_id: str | None = None,
) -> None:
renderer = cls.get_renderer(notification_type=template.notification_type)
notification_content = renderer.render(data=data, template=template)
cls._send_notification(
notification_content=notification_content,
notification_type=template.notification_type,
target=target,
thread_id=thread_id,
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows us to sidestep the generic type ambiguity issues we saw before, since we can guarantee the RenderableT typing here via the cls type.

Comment on lines +30 to +31
default_renderer: NotificationRenderer[RenderableT]
target_class: type[NotificationTarget]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added future annotations to alleviate this, though I'm not sure we needed quoted forward declarations for these before?

Copy link

codecov bot commented Jun 18, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 3 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/notifications/platform/provider.py 76.92% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #93880       +/-   ##
===========================================
+ Coverage   64.03%   88.03%   +24.00%     
===========================================
  Files       10333    10337        +4     
  Lines      596791   596930      +139     
  Branches    23196    23196               
===========================================
+ Hits       382134   525534   +143400     
+ Misses     214198    70937   -143261     
  Partials      459      459               

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant