From c6fb835783287d1d8da324ee76ffa87eeac80dcc Mon Sep 17 00:00:00 2001 From: Jason Schroth Date: Mon, 8 Jan 2024 15:23:01 -0800 Subject: [PATCH] Check for case assignee before trying to send reminder (#4218) * Check for case assignee before trying to send reminder Updated return types for definitions, changed None checks to use "is None" instead of "not" and added a None check for assignee when sending case close reminders * Update src/dispatch/case/messaging.py Co-authored-by: David Whittaker <84562015+whitdog47@users.noreply.github.com> --------- Co-authored-by: David Whittaker <84562015+whitdog47@users.noreply.github.com> --- src/dispatch/case/messaging.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/dispatch/case/messaging.py b/src/dispatch/case/messaging.py index ae9d54a02a15..edea511bc6be 100644 --- a/src/dispatch/case/messaging.py +++ b/src/dispatch/case/messaging.py @@ -20,7 +20,7 @@ log = logging.getLogger(__name__) -def send_case_close_reminder(case: Case, db_session: SessionLocal): +def send_case_close_reminder(case: Case, db_session: SessionLocal) -> None: """ Sends a direct message to the assignee reminding them to close the case if possible. """ @@ -30,9 +30,12 @@ def send_case_close_reminder(case: Case, db_session: SessionLocal): plugin = plugin_service.get_active_instance( db_session=db_session, project_id=case.project.id, plugin_type="conversation" ) - if not plugin: + if plugin is None: log.warning("Case close reminder message not sent. No conversation plugin enabled.") return + if case.assignee is None: + log.warning(f"Case close reminder message not sent. No assignee for {case.name}.") + return items = [ { @@ -54,7 +57,7 @@ def send_case_close_reminder(case: Case, db_session: SessionLocal): log.debug(f"Case close reminder sent to {case.assignee.individual.email}.") -def send_case_triage_reminder(case: Case, db_session: SessionLocal): +def send_case_triage_reminder(case: Case, db_session: SessionLocal) -> None: """ Sends a direct message to the assignee reminding them to triage the case if possible. """ @@ -64,12 +67,12 @@ def send_case_triage_reminder(case: Case, db_session: SessionLocal): plugin = plugin_service.get_active_instance( db_session=db_session, project_id=case.project.id, plugin_type="conversation" ) - if not plugin: + if plugin is None: log.warning("Case triage reminder message not sent. No conversation plugin enabled.") return - if not case.assignee: - log.warning("Case triage reminder message not sent. No assignee.") + if case.assignee is None: + log.warning(f"Case triage reminder message not sent. No assignee for {case.name}.") return items = [