From 836cac56ad80bfd9ff43d3007b1f71d5f752bacb Mon Sep 17 00:00:00 2001 From: Avery Date: Sat, 27 Jan 2024 10:57:18 -0800 Subject: [PATCH] Bugfix/do not overwrite stable at (#4301) * Fixes race condition where the updated incident is marked as stable, but the update flow has not yet completed. * Reduces likelihood of incident_update_flow() running before incident_service.update() completes. * Adds a check to only set the stable at field if the incident is not active and the stable_at field has not been set yet. * Restores previous version of incident update functions --- src/dispatch/incident_cost/service.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dispatch/incident_cost/service.py b/src/dispatch/incident_cost/service.py index 3c3ab5b7acc4..f2377f7bb889 100644 --- a/src/dispatch/incident_cost/service.py +++ b/src/dispatch/incident_cost/service.py @@ -225,7 +225,8 @@ def calculate_incident_response_cost_with_classic_model(incident: Incident, inci participant_role_renounced_at = participant_role.renounced_at else: # Fixes race condition where the updated incident is marked as stable, but the update flow has not yet completed. - incident.stable_at = datetime.utcnow() + if not incident.stable_at: + incident.stable_at = datetime.utcnow() # we set the renounced_at default time to the stable_at time participant_role_renounced_at = incident.stable_at