Fix MultiValueDictKeyError when radio group is unselected in save_set…#366
Fix MultiValueDictKeyError when radio group is unselected in save_set…#366jamesmulcahy wants to merge 1 commit intoNSPManager:develfrom
Conversation
…tings Radio button groups (optimistic_mode, show_screensaver_inside/outside_temperature, turn_on_behavior) are absent from POST data when neither option is pre-selected (e.g. fresh install with no stored value). Use .get() with safe defaults instead of hard dict access to avoid MultiValueDictKeyError. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
After upgrading to the latest beta, I updated some settings in the UI, and hit save, and hit this error in Django, as it's assuming some fields are already set. |
tpanajott
left a comment
There was a problem hiding this comment.
Looks like a nice patch, thanks. Please see review for a few quick things before merging.
| set_setting_value( | ||
| name="show_screensaver_inside_temperature", | ||
| value=request.POST["show_screensaver_inside_temperature"], | ||
| value=request.POST.get("show_screensaver_inside_temperature", "False"), |
There was a problem hiding this comment.
We want to keep this to "True". We always want to show inside default as default.
| set_setting_value( | ||
| name="show_screensaver_outside_temperature", | ||
| value=request.POST["show_screensaver_outside_temperature"], | ||
| value=request.POST.get("show_screensaver_outside_temperature", "False"), |
There was a problem hiding this comment.
We want to keep this to "True". We always want to show outside default as default.
| set_setting_value( | ||
| name="optimistic_mode", value=request.POST["optimistic_mode"] == "optimistic" | ||
| name="optimistic_mode", | ||
| value=request.POST.get("optimistic_mode", "") == "optimistic", |
There was a problem hiding this comment.
We want to keep optimistic mode as the default. So, adding "optimistic" to be the default in case it was not found would seem appropriate. Or perhaps even better, checking of "optimistic_mode" in request.POST before trying to access it as it would then not change a value in case it was missing in the request but actually set in the stored settings.
|
Having thought a bit more about this i find it strange that this issue would pop up. Sure it needs to be fixed but it shouldn't happen. When the manager first starts it will go through the database and remove any setting that exists but is no longer used and will set the default value in case it does not exist. This functionality can be seen here: It seems there may be some issue with the check in the Django template if it should check a radio box or not. |
…tings
Radio button groups (optimistic_mode, show_screensaver_inside/outside_temperature, turn_on_behavior) are absent from POST data when neither option is pre-selected (e.g. fresh install with no stored value). Use .get() with safe defaults instead of hard dict access to avoid MultiValueDictKeyError.