From b9233ff1c28e68bfe3ff9284c660e671fceb0af4 Mon Sep 17 00:00:00 2001 From: Sandeep Chauhan <sandeepsajan0@gmail.com> Date: Fri, 12 Apr 2024 13:57:14 +0530 Subject: [PATCH] Handle missing related object in task for todo list (#3862) Fixes https://otf.sentry.io/issues/5013342091/events/e636f260d01640e897414eec5ac884eb/ Looks like we have deleted something from the test site and that shouldn't be the case in prod but still no harm to have better error handling. --- hypha/apply/todo/options.py | 6 +++++- hypha/apply/todo/views.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/hypha/apply/todo/options.py b/hypha/apply/todo/options.py index 1fa7cb5f4..6d8b6a325 100644 --- a/hypha/apply/todo/options.py +++ b/hypha/apply/todo/options.py @@ -137,12 +137,16 @@ template_map = { def get_task_template(request, code, related_obj, **kwargs): + # if related_object is none/deleted and task remain there(edge case, avoiding 500) + if not related_obj: + return None + templates = copy.deepcopy(template_map) try: template = templates[code] except KeyError: # Unregistered code - return + return None template_kwargs = { "related": related_obj, "link": link_to(related_obj, request), diff --git a/hypha/apply/todo/views.py b/hypha/apply/todo/views.py index 276b770cb..4ec9f2d00 100644 --- a/hypha/apply/todo/views.py +++ b/hypha/apply/todo/views.py @@ -135,4 +135,5 @@ def render_task_templates_for_user(request, user): get_task_template(request, code=task.code, related_obj=task.related_object) for task in tasks ] - return templates + + return list(filter(None, templates)) -- GitLab