From ba4301fc4629023b51aedef45b27ad448a6b16f5 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 13 Jan 2025 14:21:43 -0800 Subject: [PATCH] fix bug with created_at --- app/celery/scheduled_tasks.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index a7fe15b75..e3daa0201 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -315,6 +315,8 @@ def batch_insert_notifications(self): notification_dict["status"] = notification_dict.pop("notification_status") if not notification_dict.get("created_at"): notification_dict["created_at"] = utc_now() + elif isinstance(notification_dict["created_at"], list): + notification_dict["created_at"] = notification_dict["created_at"][0] notification = Notification(**notification_dict) if notification is not None: batch.append(notification) @@ -324,7 +326,10 @@ def batch_insert_notifications(self): current_app.logger.exception("Notification batch insert failed") for n in batch: # Use 'created_at' as a TTL so we don't retry infinitely - if datetime.fromisoformat(n.created_at) < utc_now() - timedelta(seconds=50): + notification_time = n.created_at + if isinstance(notification_time, str): + notification_time = datetime.fromisoformat(n.created_at) + if notification_time < utc_now() - timedelta(seconds=50): current_app.logger.warning( f"Abandoning stale data, could not write to db: {n.serialize_for_redis(n)}" )