From 9fb356bf45de44118e251ccfa2c2fb370bc8d997 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Mon, 12 Aug 2024 12:31:49 +1000 Subject: [PATCH] sheetsync: Better error handling for running out of space when creating rows --- sheetsync/sheetsync/sheets.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sheetsync/sheetsync/sheets.py b/sheetsync/sheetsync/sheets.py index 391fc64..a8d8dfd 100644 --- a/sheetsync/sheetsync/sheets.py +++ b/sheetsync/sheetsync/sheets.py @@ -129,6 +129,8 @@ class SheetsMiddleware(): } # tracks when to do inactive checks self.sync_count = 0 + # tracks empty rows on the sheet for us to create new rows in + self.unassigned_rows = {} def parse_bustime(self, value, preserve_dash=False): """Convert from HH:MM or HH:MM:SS format to datetime. @@ -261,7 +263,10 @@ class SheetsMiddleware(): self.worksheets[row["sheet_name"]] = monotonic() def create_row(self, worksheet, id): - index = self.unassigned_rows[worksheet].pop(0) + unassigned_rows = self.unassigned_rows.get(worksheet, []) + if not unassigned_rows: + raise Exception(f"Worksheet {worksheet} has no available space to create a new row in") + index = unassigned_rows.pop(0) row = { "sheet_name": worksheet, "id": id,