From bf4cefc6e66bea5d4601c517692e18a8be54c5e1 Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Sat, 1 Mar 2025 15:30:38 -0800
Subject: [PATCH] Fix: handle null workflow body and email subject

---
 src/documents/signals/handlers.py | 54 ++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 23 deletions(-)

diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py
index 78d0043b5..1fd34dd81 100644
--- a/src/documents/signals/handlers.py
+++ b/src/documents/signals/handlers.py
@@ -1002,29 +1002,37 @@ def run_workflows(
             added = timezone.localtime(timezone.now())
             created = timezone.localtime(overrides.created)
 
-        subject = parse_w_workflow_placeholders(
-            action.email.subject,
-            correspondent,
-            document_type,
-            owner_username,
-            added,
-            filename,
-            current_filename,
-            created,
-            title,
-            doc_url,
+        subject = (
+            parse_w_workflow_placeholders(
+                action.email.subject,
+                correspondent,
+                document_type,
+                owner_username,
+                added,
+                filename,
+                current_filename,
+                created,
+                title,
+                doc_url,
+            )
+            if action.email.subject
+            else ""
         )
-        body = parse_w_workflow_placeholders(
-            action.email.body,
-            correspondent,
-            document_type,
-            owner_username,
-            added,
-            filename,
-            current_filename,
-            created,
-            title,
-            doc_url,
+        body = (
+            parse_w_workflow_placeholders(
+                action.email.body,
+                correspondent,
+                document_type,
+                owner_username,
+                added,
+                filename,
+                current_filename,
+                created,
+                title,
+                doc_url,
+            )
+            if action.email.body
+            else ""
         )
         try:
             n_messages = send_email(
@@ -1105,7 +1113,7 @@ def run_workflows(
                             f"Error occurred parsing webhook params: {e}",
                             extra={"group": logging_group},
                         )
-            else:
+            elif action.webhook.body:
                 data = parse_w_workflow_placeholders(
                     action.webhook.body,
                     correspondent,