From 40a3fe49bed3d4b710ad19fe6dc361111e650c7e Mon Sep 17 00:00:00 2001 From: thenav56 Date: Wed, 8 Oct 2025 14:41:32 +0545 Subject: [PATCH] chore(index_and_notify): use exc_info and logger_context with logger.error --- api/management/commands/index_and_notify.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/api/management/commands/index_and_notify.py b/api/management/commands/index_and_notify.py index ffedb6d52..ff6c1fcf2 100644 --- a/api/management/commands/index_and_notify.py +++ b/api/management/commands/index_and_notify.py @@ -24,6 +24,7 @@ ) from deployments.models import ERU, Personnel, PersonnelDeployment from main.sentry import SentryMonitor +from main.utils import logger_context from notifications.hello import get_hello from notifications.models import RecordType, Subscription, SubscriptionType, SurgeAlert from notifications.notification import send_notification @@ -922,12 +923,16 @@ def index_records(self, records, to_create=True): def bulk(self, actions): try: created, errors = bulk(client=ES_CLIENT, actions=actions) - if len(errors): - logger.error("Produced the following errors:") - logger.error("[%s]" % ", ".join(map(str, errors))) - except Exception as e: - logger.error("Could not index records") - logger.error("%s..." % str(e)[:512]) + if errors: + logger.error( + "(index_and_notify:bulk): produced errors:", + extra=logger_context(dict(errors=errors)), + ) + except Exception: + logger.error( + "(index_and_notify:bulk): could not index records", + exc_info=True, + ) # Remove items in a queryset where updated_at == created_at. # This leaves us with only ones that have been modified.