From 20239d72c83f5a1a56e6061f7695fbf76d031c68 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Tue, 10 Feb 2026 21:35:41 +1100 Subject: [PATCH] put improved foreign key constraints on DB to fix bug where when I delete a cset, that was being used to compare_to, it breaks --- BUGS | 2 -- db.py | 2 ++ main.py | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/BUGS b/BUGS index d22d124..fd43a79 100644 --- a/BUGS +++ b/BUGS @@ -1,5 +1,3 @@ -* when I delete a comp_set && it is the current compare_to, then need to reset compare_to to 'Nothing' - * with future bills - recalculate bills button blows away growth! - BUT, I think just loading the bills page puts it back -- need to validate and fix if so diff --git a/db.py b/db.py index bd2b2f2..68a232f 100644 --- a/db.py +++ b/db.py @@ -8,6 +8,8 @@ def connect_db(as_object): conn = sqlite3.connect('/data/finance.db') else: conn = sqlite3.connect('./finance.db') + # allow deleting cset to clear our compare_to properly in finance table + conn.execute("PRAGMA foreign_keys = ON;") if as_object: conn.row_factory = sqlite3.Row # This allows us to access columns by name return conn diff --git a/main.py b/main.py index 2d2421c..dc5e059 100644 --- a/main.py +++ b/main.py @@ -41,7 +41,10 @@ def index(): depletion_date=depletion_date.date(); # just show date # if we are comparing...(compare_to will be 0 / None to start with, and then COMP will be None - COMP=get_comp_set_data(finance_data['compare_to']) + if finance_data['compare_to']: + COMP=get_comp_set_data(finance_data['compare_to']) + else: + COMP={} DISP=[] # Row 1 @@ -122,6 +125,9 @@ def update(): old_finance_data = get_finance_data() + raw_compare_to = request.form.get('compare_to') + compare_to_value = None if raw_compare_to == "0" else int(raw_compare_to) + finance_data = ( request.form['D_Salary'], request.form['D_Num_fortnights_pay'], @@ -147,9 +153,10 @@ def update(): request.form['Mark_reno_date'], request.form['Car_buyout_date'], request.form['Sell_shares'], - request.form['compare_to'], + compare_to_value, request.form['Ioniq6_future'] ) + update_finance(finance_data) new_finance_data = get_finance_data() # changed Ioniq6_future, Car_buyout_date or D_Num_fortnights_pay, so lets force recalc key_dates, and therefore estimated bills