Skip to content

Prevent settings files being overwritten before they are read.#384

Merged
rwb27 merged 4 commits into
mainfrom
fix-settings-during-init
Jul 2, 2026
Merged

Prevent settings files being overwritten before they are read.#384
rwb27 merged 4 commits into
mainfrom
fix-settings-during-init

Conversation

@rwb27

@rwb27 rwb27 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

#383 describes a bug where settings files were overwritten if a setting was written to before load_settings was called.

This PR changes the initial value of _disable_saving_settings such that the settings file will only be written to after it has been loaded.

The first commit introduces a failing test. The second commit fixes it.

I've verified that this fixes the problem on an actual OpenFlexure Microscope.

I've also updated the docs for settings to note that settings modified during __init__ may get overwritten when they are loaded.

Change in behaviour

Data Settings

The behaviour change is pretty minor: before #256, writing to a data setting during __init__ would result in an exception. The value would be changed, but the exception prevented it being written to disk.

After #256 the exception was gone, and #383 appeared, overwriting settings files.

After this PR, the exception will not come back, but the setting won't write to disk - i.e. we've more or less reverted to the original behaviour.

Functional Settings

There is a behaviour change for functional settings, which didn't raise the exception prior to #256. The old behaviour wasn't specified, but the new behaviour is documented in the section on settings.

rwb27 added 2 commits July 2, 2026 11:44
This tests for #383, currently it fails when a setting is written during `__init__`.
Writing to a setting will now not update the settings file, until the settings file has been loaded.

This fixes #383 where settings files would be overwritten with defaults, if a setting was written during `__init__`.
@barecheck

barecheck Bot commented Jul 2, 2026

Copy link
Copy Markdown

Barecheck - Code coverage report

Total: 97.31%

Your code coverage diff: 0.00% ▴

Uncovered files and lines
FileLines
src/labthings_fastapi/thing.py297, 369-371, 462

Comment thread src/labthings_fastapi/thing.py Outdated
rwb27 added 2 commits July 2, 2026 13:19
I've added a note to the docs on settings to explain that they may be overwritten after ``__init__`` has finished.
@rwb27 rwb27 force-pushed the fix-settings-during-init branch from c274472 to a93e082 Compare July 2, 2026 12:25
@rwb27 rwb27 requested a review from julianstirling July 2, 2026 12:42
@rwb27 rwb27 merged commit d6eb0a2 into main Jul 2, 2026
16 checks passed
@rwb27 rwb27 deleted the fix-settings-during-init branch July 2, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants