From 872cb071eadf8cf39b5991cc2e992c56b339577b Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Sun, 2 Aug 2020 16:21:47 +0200
Subject: [PATCH] Delay sending of notification until it's saved in database

---
 aleksis/core/models.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/aleksis/core/models.py b/aleksis/core/models.py
index 8910d5abe..bd1cfe12d 100644
--- a/aleksis/core/models.py
+++ b/aleksis/core/models.py
@@ -9,7 +9,7 @@ from django.contrib.contenttypes.fields import GenericForeignKey
 from django.contrib.contenttypes.models import ContentType
 from django.contrib.sites.models import Site
 from django.core.exceptions import ValidationError
-from django.db import models
+from django.db import models, transaction
 from django.db.models import QuerySet
 from django.forms.widgets import Media
 from django.urls import reverse
@@ -456,7 +456,7 @@ class Notification(ExtensibleModel):
     def save(self, **kwargs):
         super().save(**kwargs)
         if not self.sent:
-            send_notification(self.pk, resend=True)
+            transaction.on_commit(lambda: send_notification(self.pk, resend=True))
         self.sent = True
         super().save(**kwargs)
 
-- 
GitLab