From a5e2b9e745185ee88cbb685ff58c71d66ff2fe50 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Sun, 10 Nov 2024 19:22:21 -0800 Subject: [PATCH] Exit early when running an automation if the conversation for the automation does not exist. --- src/khoj/routers/helpers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index d89ed147..ca78ba35 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -1582,6 +1582,11 @@ def scheduled_chat( # encode the conversation_id to avoid any issues with special characters query_dict["conversation_id"] = [quote(str(conversation_id))] + # validate that the conversation id exists. If not, delete the automation and exit. + if not ConversationAdapters.get_conversation_by_id(conversation_id): + AutomationAdapters.delete_automation(user, job_id) + return + # Restructure the original query_dict into a valid JSON payload for the chat API json_payload = {key: values[0] for key, values in query_dict.items()}