From 7bd85ba3355f47de734df4605a52b973820f4496 Mon Sep 17 00:00:00 2001 From: Hendrik Borras Date: Mon, 8 Jan 2018 18:46:51 +0100 Subject: [PATCH] Protection against invalid type returned from sqlite --- backend/mqtt_publisher.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/mqtt_publisher.py b/backend/mqtt_publisher.py index 7fa440a..6e8a9b4 100644 --- a/backend/mqtt_publisher.py +++ b/backend/mqtt_publisher.py @@ -77,7 +77,16 @@ while(True): # get the most recent time cursor.execute("SELECT * FROM Events ORDER BY UTCUnixTime DESC, SubSeconds DESC;") - latest_time = cursor.fetchone()[0] + time_row = cursor.fetchone() + # ToDo: Popper protection against an empty DB, this isn't working for some reason, but systemd will restart the program, so it's not completly deadly... + if time_row == type(None): + log.info("Got a none type, retrying in a bit") + # sleep for a semi random time + time_to_wait = int(random.randrange(30, 90)) + log.info("Sleeping for: {} [s]".format(time_to_wait)) + time.sleep(time_to_wait) + continue + latest_time = time_row[0] # Get the next events that will be sent cursor.execute("SELECT * FROM Events WHERE UTCUnixTime > ?;", (last_sent_event_timestamp,))