Bugfix settings machine vars not persisting on subsequent data writes #1708
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.
This PR fixes a bug that would occasionally (okay, often) forget saved machine vars and cause operator-configured settings to reset to default. After much digging and consternation, I believe I've figured out the cause and it's a simple fix.
The Background
When MPF initializes, it first reads all machine variables from the machine_vars.yaml file and then appends those with the (default) variables from the
machine_variables:
config section. All settings values are backed under-the-hood by machine variables, so this logic covers operator-adjustable settings as well.The Bug
While the code flow for loading machine vars from config section includes the configuration of a
persist
value, loading machine vars from the data file does not, which means all saved settings are defaulted topersist: False
. Which is okay for a short while, but eventually something else is going to write an update to the persisted data (a new setting adjustment, or a player score, or something).The Impact
The way the logic of writing the data works is that the code looks through all the machine vars, finds all of the ones that are
persist: True
, and writes a complete new data file with those values. Remember from before that values previously loaded from the data file arepersist: False
, so all of those values get wiped.The Fix
This PR tweaks the flow for loading persisted values from a data file, explicitly flagging them each as
persist: True
in the machine variables controller. After all, if the value was persisted before, it should be persisted still, right?The updated persistence logic takes place after data validation and expiration checks, so it shouldn't impact data retention policies, and it fixes the issue of saved settings being forgotten on subsequent data writes.