From 820c84287cc3c2f83b174400d48ca54a7cb89bc2 Mon Sep 17 00:00:00 2001 From: Horilla Date: Thu, 24 Jul 2025 15:08:01 +0530 Subject: [PATCH] [UPDT] HORILLA_AUTOMATIONS: Prevent UnboundLocalError by safely initializing from_email and reply_to with fallback --- horilla_automations/signals.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/horilla_automations/signals.py b/horilla_automations/signals.py index 067e68b46..398084681 100644 --- a/horilla_automations/signals.py +++ b/horilla_automations/signals.py @@ -406,14 +406,19 @@ def send_mail(request, automation, instance): cc = cc_emails email_backend = ConfiguredEmailBackend() - display_email_name = email_backend.dynamic_from_email_with_display_name - if request: + default_email = email_backend.dynamic_from_email_with_display_name + + from_email = default_email + reply_to = [default_email] + + if request and hasattr(request, "user") and hasattr(request.user, "employee_get"): try: - display_email_name = f"{request.user.employee_get.get_full_name()} <{request.user.employee_get.email}>" + user = request.user.employee_get + display_email_name = f"{user.get_full_name()} <{user.email}>" from_email = display_email_name reply_to = [display_email_name] - except: - logger.error(Exception) + except Exception as e: + logger.error(f"Error generating user-based email display name: {e}") if pk_or_text and request and to_emails: attachments = []