diff --git a/taiga/projects/notifications/services.py b/taiga/projects/notifications/services.py index bc20de54..d0155eac 100644 --- a/taiga/projects/notifications/services.py +++ b/taiga/projects/notifications/services.py @@ -245,14 +245,20 @@ def send_sync_notifications(notification_id): """ notification = HistoryChangeNotification.objects.select_for_update().get(pk=notification_id) - # If the last modification is too recent we ignore it + # If the last modification is too recent we ignore it for the time being now = timezone.now() time_diff = now - notification.updated_datetime if time_diff.seconds < settings.CHANGE_NOTIFICATIONS_MIN_INTERVAL: return history_entries = tuple(notification.history_entries.all().order_by("created_at")) - history_entries = squash_history_entries(history_entries) + history_entries = list(squash_history_entries(history_entries)) + + # If there are no effective modifications we can delete this notification + # without further processing + if notification.history_type == HistoryType.change and not history_entries: + notification.delete() + return obj, _ = get_last_snapshot_for_key(notification.key) obj_class = get_model_from_key(obj.key) diff --git a/tests/integration/test_notifications.py b/tests/integration/test_notifications.py index a552cc4b..e7e9b70c 100644 --- a/tests/integration/test_notifications.py +++ b/tests/integration/test_notifications.py @@ -359,7 +359,7 @@ def test_send_notifications_using_services_method_for_user_stories(settings, mai history_change = f.HistoryEntryFactory.create( project=project, user={"pk": member1.user.id}, - comment="", + comment="test:change", type=HistoryType.change, key="userstories.userstory:{}".format(us.id), is_hidden=False, @@ -454,7 +454,7 @@ def test_send_notifications_using_services_method_for_tasks(settings, mail): history_change = f.HistoryEntryFactory.create( project=project, user={"pk": member1.user.id}, - comment="", + comment="test:change", type=HistoryType.change, key="tasks.task:{}".format(task.id), is_hidden=False, @@ -549,7 +549,7 @@ def test_send_notifications_using_services_method_for_issues(settings, mail): history_change = f.HistoryEntryFactory.create( project=project, user={"pk": member1.user.id}, - comment="", + comment="test:change", type=HistoryType.change, key="issues.issue:{}".format(issue.id), is_hidden=False, @@ -644,7 +644,7 @@ def test_send_notifications_using_services_method_for_wiki_pages(settings, mail) history_change = f.HistoryEntryFactory.create( project=project, user={"pk": member1.user.id}, - comment="", + comment="test:change", type=HistoryType.change, key="wiki.wikipage:{}".format(wiki.id), is_hidden=False,