diff --git a/src/khoj/database/adapters/__init__.py b/src/khoj/database/adapters/__init__.py index 2cd9daf7..65d2b70f 100644 --- a/src/khoj/database/adapters/__init__.py +++ b/src/khoj/database/adapters/__init__.py @@ -1794,7 +1794,7 @@ class AutomationAdapters: def get_automation(user: KhojUser, automation_id: str) -> Job: # Perform validation checks # Check if user is allowed to delete this automation id - if not automation_id.startswith(f"automation_{user.uuid}_"): + if not is_none_or_empty(automation_id) or automation_id.startswith(f"automation_{user.uuid}_"): raise ValueError("Invalid automation id") # Check if automation with this id exist automation: Job = state.scheduler.get_job(job_id=automation_id) diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index 67b367b0..58ab7385 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -1977,7 +1977,13 @@ def schedule_automation( # Run automation at some random minute (to distribute request load) instead of running every X minutes crontime = " ".join([str(math.floor(random() * 60))] + crontime.split(" ")[1:]) - user_timezone = pytz.timezone(timezone) + # Convert timezone string to timezone object + try: + user_timezone = pytz.timezone(timezone) + except pytz.UnknownTimeZoneError: + logger.error(f"Invalid timezone: {timezone}. Fallback to use UTC to schedule automation.") + user_timezone = pytz.utc + trigger = CronTrigger.from_crontab(crontime, user_timezone) trigger.jitter = 60 # Generate id and metadata used by task scheduler and process locks for the task runs