Serialize storage payload before truncating the backup file - #6188
Serialize storage payload before truncating the backup file#6188evnchn wants to merge 2 commits into
Conversation
DateInput applied .props('no-parent-event') to the inner QDate, but
Quasar 2.18.5's QDate has no such prop (noParentEvent belongs to the
anchor-props mixin behind QMenu/QTooltip). It was an inert no-op
attribute; removing it changes no behavior (open/close is driven by the
parent QMenu).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
`async_backup` opened the storage file in write mode (truncating it on
disk) before serializing the dict, so assigning a non-JSON-serializable
value (e.g. a set) made `dumps` raise *after* the file was already empty.
The valid data was lost and the next startup loaded `{}`.
Serialize first and only open the file once a good payload exists, matching
the already-safe synchronous branch below.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@falkoschindler asked me to bring the open PRs up to date with The conflict is in Assigning you to make the ownership visible. Generated by Claude Code |
|
Closing this as subsumed by #6174 — and the remaining delta turns out to be harmful rather than neutral. #6174 ("Fix PermissionError when clearing storage on Windows") introduced the temp-file + What was left here is the hoist of Probe: the mutation that gets lostWrite
The mechanism is in All 29 tests in If the leftover zero-byte |
Motivation
User does
app.storage.user['x'] = {1, 2, 3}(a set) or any non-JSON-serializable object after storage-user-.json already holds valid keys. on_change -> backup -> async_backup runs, opens the file 'w' (file now empty on disk), then dumps() raises TypeError. File is left as 0 bytes. On next server start initialize() loads {} -> the entire user's storage is permanently lost.Minimal reproduction (
nicegui/persistence/file_persistent_dict.py:52) — the exact test/script that was run to reproduce it:→
before: file = '{"a":1,"b":2}' (valid data persisted)Implementation
Serialize storage payload before opening/truncating the backup file in async_backup so a non-JSON-serializable value no longer wipes persisted data.
Verification
assert '' == '{"a":1,"b":2}'(file truncated to 0 bytes), fixed src PASSES../nicegui· pylint 10.00/10 · pytest (touched) — all green.Progress