From ae39c788f39b92ebb90ad29a3ac99fd9f0d5f918 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 13 Oct 2026 13:54:41 +1100 Subject: [PATCH] Add missing timeout to Slack notification plugin (#12990) (#13001) (cherry picked from commit 2341d5ff445de557ceb0e8e3b0ec90d1e7c456f9) Co-authored-by: MH <106589916+gotoUSA@users.noreply.github.com> Co-authored-by: Matthias Mair --- .../builtin/integration/core_notifications.py | 1 + .../integration/test_core_notifications.py | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/backend/InvenTree/plugin/builtin/integration/core_notifications.py b/src/backend/InvenTree/plugin/builtin/integration/core_notifications.py index 0b732bcb64..e21e1a54c5 100644 --- a/src/backend/InvenTree/plugin/builtin/integration/core_notifications.py +++ b/src/backend/InvenTree/plugin/builtin/integration/core_notifications.py @@ -175,6 +175,7 @@ class InvenTreeSlackNotifications(NotificationMixin, SettingsMixin, InvenTreePlu }, ], }, + timeout=10, ) return ret.ok diff --git a/src/backend/InvenTree/plugin/builtin/integration/test_core_notifications.py b/src/backend/InvenTree/plugin/builtin/integration/test_core_notifications.py index bddb848745..82e9ce1ec7 100644 --- a/src/backend/InvenTree/plugin/builtin/integration/test_core_notifications.py +++ b/src/backend/InvenTree/plugin/builtin/integration/test_core_notifications.py @@ -1,5 +1,7 @@ """Tests for core_notifications.""" +from unittest import mock + from django.core import mail from common.models import NotificationEntry @@ -61,3 +63,30 @@ class CoreNotificationTestTests(InvenTreeTestCase): self.notify() self.assertEqual(len(mail.outbox), 1) + + def test_slack_timeout(self): + """Ensure that the slack webhook call cannot block indefinitely.""" + slug = 'inventree-slack-notification' + registry.set_plugin_state(slug, True) + + plugin = registry.get_plugin(slug) + self.assertIsNotNone(plugin, 'Slack notification plugin should be available') + + plugin.set_setting('NOTIFICATION_SLACK_URL', 'https://hooks.slack.com/test') + + with mock.patch( + 'plugin.builtin.integration.core_notifications.requests.post' + ) as mock_post: + plugin.send_notification( + self.user, + 'test_notification', + [self.user], + { + 'name': 'Test Slack Notification', + 'message': 'This is a test slack notification.', + 'link': 'http://localhost:8000/', + }, + ) + + mock_post.assert_called_once() + self.assertEqual(mock_post.call_args.kwargs['timeout'], 10)