From 98d713234b7adad38ab1ed90db5bcb6cdb897709 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Tue, 20 Jan 2026 08:52:43 +0100 Subject: [PATCH] Only emit time_conflict_resolved when a conflict has actually existed --- .../BreCal/validators/validation_rules.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/server/BreCal/validators/validation_rules.py b/src/server/BreCal/validators/validation_rules.py index 454dd26..bf9ef95 100644 --- a/src/server/BreCal/validators/validation_rules.py +++ b/src/server/BreCal/validators/validation_rules.py @@ -135,15 +135,22 @@ class ValidationRules(ValidationRuleFunctions): for participant in participants: commands.execute(query, param={"shipcall_id" : int(shipcall_id), "participant_id" : participant["participant_id"], "message" : violation}) - if state_new == 1 and state_old != 0: # this resolves the time conflict + resolves_time_conflict = (state_old == StatusFlags.RED.value) and (state_new in [StatusFlags.GREEN.value, StatusFlags.YELLOW.value]) + if resolves_time_conflict: + notification_type = 3 # time_conflict logging.info(f"Resolving notifications for shipcall {shipcall_id}, type={notification_type}") - query = f"DELETE from notification where shipcall_id = ?shipcall_id? and type = {notification_type} and level = 0" - deleted_count = commands.execute(query, param={"shipcall_id" : int(shipcall_id)}) - logging.info(f"Deleted {deleted_count} existing notifications (yet unsent)") - if deleted_count == 0: + query = "SELECT COUNT(*) as cnt FROM notification WHERE shipcall_id = ?shipcall_id? AND type = ?type?" + result = commands.query(query, model=dict, param={"shipcall_id" : int(shipcall_id), "type" : notification_type}) + has_conflict_notification = (len(result) > 0) and (result[0].get("cnt", 0) > 0) + if has_conflict_notification: + query = "DELETE from notification where shipcall_id = ?shipcall_id? and type = ?type? and level = 0" + deleted_count = commands.execute(query, param={"shipcall_id" : int(shipcall_id), "type" : notification_type}) + logging.info(f"Deleted {deleted_count} existing notifications (yet unsent)") query = "INSERT INTO notification (shipcall_id, participant_id, type, level) VALUES (?shipcall_id?, ?participant_id?, 4, 0)" for participant in participants: commands.execute(query, param={"shipcall_id" : int(shipcall_id), "participant_id" : participant["participant_id"]}) + else: + logging.info(f"Skipping resolve notification for shipcall {shipcall_id} because no prior time_conflict exists") finally: if pooledConnection is not None: pooledConnection.close()