From 8bd09a22ae1c206f96ac18d657880a87e139a572 Mon Sep 17 00:00:00 2001 From: Luca Date: Sun, 7 May 2023 22:24:22 +0200 Subject: [PATCH] Fix overwriting 'read' state of IncomingMessage every time it is "received" --- shiftregister/team/tasks.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/shiftregister/team/tasks.py b/shiftregister/team/tasks.py index 8e2cfac..2bff8c2 100644 --- a/shiftregister/team/tasks.py +++ b/shiftregister/team/tasks.py @@ -16,12 +16,14 @@ def receive_messages(): from_dt = None try: - for sms in list_incoming_sms(from_dt): - IncomingMessage( + for sms in reversed(list_incoming_sms(from_dt)): + IncomingMessage.objects.get_or_create( id=sms.id, - sender=sms.sender, - content=sms.content, - created_at=sms.created_at, - ).save() + defaults={ + "content": sms.content, + "created_at": sms.created_at, + "sender": sms.sender, + }, + ) except Exception as e: sentry_sdk.capture_exception(e)