Make all JSON saves atomic (temp file + os.replace) #11

Open
opened 2026-06-06 19:58:11 +00:00 by tonym · 0 comments

Severity: high
Category: data-integrity
Location: app.py:199, bills.py:18, debts.py:126/138, sinking.py:37, income.py:31, assets.py:59, mortgage.py:19

Problem

Every save does open(path,'w') + json.dump, which truncates first. A crash/power-loss mid-write leaves an empty/partial file and the next load wipes or crashes.

Suggested fix

Write to a .tmp sibling then os.replace(tmp, path) (atomic on POSIX). Centralize as atomic_save().

Filed by automated code review.

**Severity:** high **Category:** data-integrity **Location:** `app.py:199, bills.py:18, debts.py:126/138, sinking.py:37, income.py:31, assets.py:59, mortgage.py:19` ### Problem Every save does `open(path,'w')` + `json.dump`, which truncates first. A crash/power-loss mid-write leaves an empty/partial file and the next load wipes or crashes. ### Suggested fix Write to a `.tmp` sibling then `os.replace(tmp, path)` (atomic on POSIX). Centralize as `atomic_save()`. _Filed by automated code review._
tonym added the
data-integrity
severity:high
labels 2026-06-06 19:58:11 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: bonna61/Moon-Household-Budget#11
No description provided.