From bc832fd488183e2a8dd5697a24589a240dafe8bc Mon Sep 17 00:00:00 2001 From: fleaz Date: Mon, 30 Mar 2020 21:57:47 +0200 Subject: [PATCH] autosort: Fix ZeroDivision bug when DB is empty --- info.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/info.py b/info.py index 90eb519..a560272 100644 --- a/info.py +++ b/info.py @@ -20,7 +20,10 @@ def command(): unsorted = session.query(Transaction).filter(Transaction.category_id == None).count() transactions = session.query(Transaction).count() categories = session.query(Category).count() - unsorted_percent = round(unsorted / (transactions / 100), 1) + try: + unsorted_percent = round(unsorted / (transactions / 100), 1) + except ZeroDivisionError: + unsorted_percent = 0 print(f"Transactions: {transactions}") print(f" Unsorted: {unsorted} ({unsorted_percent}%)")