From b47c261487e0349eaf646246ee3d1489f9e4a7ec Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 14 Feb 2024 16:55:21 +0100 Subject: [PATCH] added existence check to dictionary key usage --- src/server/BreCal/impl/times.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/server/BreCal/impl/times.py b/src/server/BreCal/impl/times.py index 7de18c7..5dd3851 100644 --- a/src/server/BreCal/impl/times.py +++ b/src/server/BreCal/impl/times.py @@ -143,8 +143,11 @@ def PutTimes(schemaModel): # save history data # TODO: set ETA properly user_data = check_jwt() - query = "INSERT INTO history (participant_id, shipcall_id, user_id, timestamp, eta, type, operation) VALUES (?pid?, ?scid?, ?uid?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 2, 2)" - commands.query(query, {"pid" : user_data["participant_id"], "scid" : schemaModel["shipcall_id"], "uid" : user_data["id"]}) + if "participant_id" in user_data and "id" in user_data: + query = "INSERT INTO history (participant_id, shipcall_id, user_id, timestamp, eta, type, operation) VALUES (?pid?, ?scid?, ?uid?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 2, 2)" + commands.execute(query, {"pid" : user_data["participant_id"], "scid" : schemaModel["shipcall_id"], "uid" : user_data["id"]}) + else: + logging.error("user_data does not contain participant_id or id") # if affected_rows == 1: # this doesn't work as expected