Ticket-reply notification receiver skips raw saves (loaddata made 5 duplicate notifications)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,3 +16,13 @@ class RawSaveTests(TestCase):
|
|||||||
answer = UserAnswer(user_id=1, question=q, choice=c, correct=True)
|
answer = UserAnswer(user_id=1, question=q, choice=c, correct=True)
|
||||||
post_save.send(UserAnswer, instance=answer, created=True, raw=True)
|
post_save.send(UserAnswer, instance=answer, created=True, raw=True)
|
||||||
self.assertEqual(NodeProgress.objects.count(), 0)
|
self.assertEqual(NodeProgress.objects.count(), 0)
|
||||||
|
|
||||||
|
|
||||||
|
class RawTicketReplyTests(TestCase):
|
||||||
|
def test_raw_support_reply_creates_no_notification(self):
|
||||||
|
from notifications.models import Notification
|
||||||
|
from support.models import Ticket, TicketMessage
|
||||||
|
t = Ticket.objects.create(user_id=1, subject='s')
|
||||||
|
m = TicketMessage(ticket=t, sender='support', text='x')
|
||||||
|
post_save.send(TicketMessage, instance=m, created=True, raw=True)
|
||||||
|
self.assertEqual(Notification.objects.count(), 0)
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ from .models import TicketMessage
|
|||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=TicketMessage, dispatch_uid='support_notify_ticket_reply')
|
@receiver(post_save, sender=TicketMessage, dispatch_uid='support_notify_ticket_reply')
|
||||||
def _notify_ticket_reply(sender, instance, created, **kwargs):
|
def _notify_ticket_reply(sender, instance, created, raw=False, **kwargs):
|
||||||
if not created or instance.sender != 'support':
|
# raw=True: loaddata (انتقال به Postgres)؛ اعلانِ آن پیامها خودش در فایل است و اینجا دوباره ساخته میشد.
|
||||||
|
if raw or not created or instance.sender != 'support':
|
||||||
return
|
return
|
||||||
from notifications.services import notify
|
from notifications.services import notify
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user