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)
|
||||
post_save.send(UserAnswer, instance=answer, created=True, raw=True)
|
||||
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')
|
||||
def _notify_ticket_reply(sender, instance, created, **kwargs):
|
||||
if not created or instance.sender != 'support':
|
||||
def _notify_ticket_reply(sender, instance, created, raw=False, **kwargs):
|
||||
# raw=True: loaddata (انتقال به Postgres)؛ اعلانِ آن پیامها خودش در فایل است و اینجا دوباره ساخته میشد.
|
||||
if raw or not created or instance.sender != 'support':
|
||||
return
|
||||
from notifications.services import notify
|
||||
|
||||
|
||||
Reference in New Issue
Block a user