Make missing default values check on save configurable #321
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.
Based on #313 (comment), this PR adds a config option to skip checking non-migrated default values when saving settings.
Reasoning
The idea is to allow using saving settings even if migrations take a while to complete, or when one does not want to use settings migrations at all.
The latter may sound odd at first, but when Settings classes declare default values, it would allow adding new settings without creating migrations. The new settings with their default values would be "migrated" just-in-time, when the user first saves the settings. This is especially helpful in multi-tenancy apps, where each tenant (user) has their own set of settings.
Backgrounnd
I don't really see a reason to throw an exception when trying to save settings with default values, if there's nothing in the database 🤔 ...
Perhaps I am missing something, but this PR does not change the default behaviour, it only provides a lever for those of us who like to live on the edge 😂
Naming and docs
Please note that there's no docs yet, as I wanted to gauge if a PR like this would even be considered, first. If the general approach is acceptable, we can discuss naming and implementation details, and then write the docs.
Misc
At first, I thought of using a generic
throw_on_missing_settings
config value, but realized that would mean if a settings class does not have default values defined, then accessing such a property, or converting the class to an array would still throw a runtime error, so it wouldn't really buy anything.