88from dispatch .case .messaging import send_case_welcome_participant_message
99from dispatch .case .models import CaseRead
1010from dispatch .conversation import flows as conversation_flows
11- from dispatch .database .core import SessionLocal
1211from dispatch .decorators import background_task
1312from dispatch .document import flows as document_flows
1413from dispatch .enums import DocumentResourceTypes , EventType , Visibility
4544log = logging .getLogger (__name__ )
4645
4746
48- def get_case_participants_flow (case : Case , db_session : SessionLocal ):
47+ def get_case_participants_flow (case : Case , db_session : Session ):
4948 """Get additional case participants based on priority, type and description."""
5049 individual_contacts = []
5150 team_contacts = []
@@ -336,7 +335,11 @@ def case_update_flow(
336335 # we get the case
337336 case = get (db_session = db_session , case_id = case_id )
338337
339- if reporter_email and case and reporter_email != case .reporter .individual .email :
338+ if not case :
339+ log .warning (f"Case with id { case_id } not found." )
340+ return
341+
342+ if reporter_email and case .reporter and reporter_email != case .reporter .individual .email :
340343 # we run the case assign role flow for the reporter if it changed
341344 case_assign_role_flow (
342345 case_id = case .id ,
@@ -345,7 +348,7 @@ def case_update_flow(
345348 db_session = db_session ,
346349 )
347350
348- if assignee_email and case and assignee_email != case .assignee .individual .email :
351+ if assignee_email and case . assignee and assignee_email != case .assignee .individual .email :
349352 # we run the case assign role flow for the assignee if it changed
350353 case_assign_role_flow (
351354 case_id = case .id ,
@@ -374,15 +377,15 @@ def case_update_flow(
374377
375378 if case .tactical_group :
376379 # we update the tactical group
377- if reporter_email and reporter_email != case .reporter .individual .email :
380+ if reporter_email and case . reporter and reporter_email != case .reporter .individual .email :
378381 group_flows .update_group (
379382 subject = case ,
380383 group = case .tactical_group ,
381384 group_action = GroupAction .add_member ,
382385 group_member = reporter_email ,
383386 db_session = db_session ,
384387 )
385- if assignee_email and assignee_email != case .assignee .individual .email :
388+ if assignee_email and case . assignee and assignee_email != case .assignee .individual .email :
386389 group_flows .update_group (
387390 subject = case ,
388391 group = case .tactical_group ,
@@ -405,7 +408,7 @@ def case_update_flow(
405408 send_case_update_notifications (case , previous_case , db_session )
406409
407410
408- def case_delete_flow (case : Case , db_session : SessionLocal ):
411+ def case_delete_flow (case : Case , db_session : Session ):
409412 """Runs the case delete flow."""
410413 # we delete the external ticket
411414 if case .ticket :
0 commit comments