From b6220a63c64aaf9fd5ca8a54f720585f922106fc Mon Sep 17 00:00:00 2001 From: Leander Rodrigues Date: Fri, 7 Nov 2025 14:06:37 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix=20import=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sentry/notifications/apps.py | 20 ++++++++-------- .../platform/templates/__init__.py | 4 ++++ .../platform/{ => templates}/sample.py | 0 tests/sentry/notifications/test_apps.py | 23 +++++++++++++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 src/sentry/notifications/platform/templates/__init__.py rename src/sentry/notifications/platform/{ => templates}/sample.py (100%) create mode 100644 tests/sentry/notifications/test_apps.py diff --git a/src/sentry/notifications/apps.py b/src/sentry/notifications/apps.py index 2184060fa175d4..9ab152940c27ea 100644 --- a/src/sentry/notifications/apps.py +++ b/src/sentry/notifications/apps.py @@ -5,14 +5,14 @@ class Config(AppConfig): name = "sentry.notifications" def ready(self) -> None: - import sentry.notifications.platform.sample # NOQA + # Register the NotificationProviders for the legacy platform + import sentry.integrations.msteams.notifications # noqa: F401 + import sentry.integrations.slack.notifications # noqa: F401 + import sentry.mail.notifications # noqa: F401 - # Register the NotificationProviders for the platform - from sentry.notifications.platform.discord.provider import ( # NOQA - DiscordNotificationProvider, - ) - from sentry.notifications.platform.email.provider import EmailNotificationProvider # NOQA - from sentry.notifications.platform.msteams.provider import ( # NOQA - MSTeamsNotificationProvider, - ) - from sentry.notifications.platform.slack.provider import SlackNotificationProvider # NOQA + # Register the providers and templates for the new platform + import sentry.notifications.platform.discord.provider # noqa: F401 + import sentry.notifications.platform.email.provider # noqa: F401 + import sentry.notifications.platform.msteams.provider # noqa: F401 + import sentry.notifications.platform.slack.provider # noqa: F401 + import sentry.notifications.platform.templates # noqa: F401 diff --git a/src/sentry/notifications/platform/templates/__init__.py b/src/sentry/notifications/platform/templates/__init__.py new file mode 100644 index 00000000000000..aa845e6e05e485 --- /dev/null +++ b/src/sentry/notifications/platform/templates/__init__.py @@ -0,0 +1,4 @@ +# All templates should be imported here so they are registered in the notifications Django app. +# See sentry/notifications/apps.py + +from .sample import * # noqa: F401,F403 diff --git a/src/sentry/notifications/platform/sample.py b/src/sentry/notifications/platform/templates/sample.py similarity index 100% rename from src/sentry/notifications/platform/sample.py rename to src/sentry/notifications/platform/templates/sample.py diff --git a/tests/sentry/notifications/test_apps.py b/tests/sentry/notifications/test_apps.py new file mode 100644 index 00000000000000..c1ffecd59eb8db --- /dev/null +++ b/tests/sentry/notifications/test_apps.py @@ -0,0 +1,23 @@ +from sentry.integrations.types import ExternalProviders +from sentry.notifications.platform.types import NotificationProviderKey +from sentry.testutils.cases import TestCase + + +class NotificationsDjangoAppTest(TestCase): + + def test_registers_legacy_providers(self) -> None: + from sentry.notifications.notify import registry + + assert len(registry) == 3 + assert registry[ExternalProviders.EMAIL] is not None + assert registry[ExternalProviders.SLACK] is not None + assert registry[ExternalProviders.MSTEAMS] is not None + + def test_registers_platform_providers(self) -> None: + from sentry.notifications.platform.registry import provider_registry + + assert len(provider_registry.registrations) == 4 + assert provider_registry.get(NotificationProviderKey.DISCORD) is not None + assert provider_registry.get(NotificationProviderKey.EMAIL) is not None + assert provider_registry.get(NotificationProviderKey.MSTEAMS) is not None + assert provider_registry.get(NotificationProviderKey.SLACK) is not None From 56260f9fe5cbea7ddecba8d75ea3cac6cf278006 Mon Sep 17 00:00:00 2001 From: Leander Rodrigues Date: Fri, 7 Nov 2025 14:25:43 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=85=20side-step=20broken=20imports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sentry/integrations/msteams/__init__.py | 1 + src/sentry/notifications/apps.py | 5 ----- tests/sentry/notifications/test_apps.py | 8 ++++++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/sentry/integrations/msteams/__init__.py b/src/sentry/integrations/msteams/__init__.py index bb14961b9ff4d2..1a03c043b5ca16 100644 --- a/src/sentry/integrations/msteams/__init__.py +++ b/src/sentry/integrations/msteams/__init__.py @@ -1,5 +1,6 @@ from sentry.integrations.msteams.spec import MsTeamsMessagingSpec from .handlers import MSTeamsActionHandler # noqa: F401,F403 +from .notifications import * # noqa: F401,F403 MsTeamsMessagingSpec().initialize() diff --git a/src/sentry/notifications/apps.py b/src/sentry/notifications/apps.py index 9ab152940c27ea..e4be76f88a81fe 100644 --- a/src/sentry/notifications/apps.py +++ b/src/sentry/notifications/apps.py @@ -5,11 +5,6 @@ class Config(AppConfig): name = "sentry.notifications" def ready(self) -> None: - # Register the NotificationProviders for the legacy platform - import sentry.integrations.msteams.notifications # noqa: F401 - import sentry.integrations.slack.notifications # noqa: F401 - import sentry.mail.notifications # noqa: F401 - # Register the providers and templates for the new platform import sentry.notifications.platform.discord.provider # noqa: F401 import sentry.notifications.platform.email.provider # noqa: F401 diff --git a/tests/sentry/notifications/test_apps.py b/tests/sentry/notifications/test_apps.py index c1ffecd59eb8db..744d36f3a690aa 100644 --- a/tests/sentry/notifications/test_apps.py +++ b/tests/sentry/notifications/test_apps.py @@ -6,6 +6,14 @@ class NotificationsDjangoAppTest(TestCase): def test_registers_legacy_providers(self) -> None: + """ + This django app doesn't actually register these legacy providers because it would result + in some circular breakages from all the __init__.py imports. We'll still test it here + to make sure it doesn't break in the future. + + If this test is failing for you, ensure all `@register_notification_provider` decorators + are triggered by an initialization import. + """ from sentry.notifications.notify import registry assert len(registry) == 3