Prevent settings files being overwritten before they are read.#384
Merged
Conversation
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 - Code coverage reportTotal: 97.31%Your code coverage diff: 0.00% ▴ Uncovered files and lines
|
I've added a note to the docs on settings to explain that they may be overwritten after ``__init__`` has finished.
c274472 to
a93e082
Compare
bprobert97
approved these changes
Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#383 describes a bug where settings files were overwritten if a setting was written to before
load_settingswas called.This PR changes the initial value of
_disable_saving_settingssuch 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.