Repository navigation
fix(config): refuse camera settings without a storage device - #3448
JamBalaya56562 wants to merge 1 commit into
Conversation
|
Is the frontend validation not supposed to prevent to apply settings, if a disabled storage option is selected? That should be the case at least. With that, I actually prefer the backend to throw an error, instead of just silently keeping the old storage, as obviously an invalid storage option was sent. If we want to handle null/None values in the backend, where actual values are expected, then with a proper validator, instead of on per-key basis. But IMO this should be prevented in our frontend in the fist place. Or, to make the backend robust against this None value: elif data.get('@storage_device', '').startswith('local-disk')In this particular case, |
a109bb7 to
94afce2
Compare
|
Yes, since #3380 the frontend blocks applying a disabled storage option, whether the File Storage section is collapsed or not, so the UI no longer sends |
|
That should be fine. Though, the check at the top of the function looks very stray there. I suggest one of two things:
|
motion_camera_ui_to_dict() raised an AttributeError on None.startswith() for "storage_device": null and a KeyError when the field was missing, and silently stored an empty storage device. The UI no longer sends null for a disabled storage option since the frontend validation blocks it, but other clients still can. Add input_required(), which returns a set value and raises a ValueError for a missing key, None or '' (False and 0 count as set), and use it where the storage device is put into the camera config. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94afce2 to
7fdf8db
Compare
|
Went with the second option: a new |
What
Camera settings whose
storage_deviceisnull, empty or missing are refused with aValueError(Setting "storage_device" must be set). A newinput_required(ui, key)next toinput_sanity_check()returns a set value and raises for a missing key,Noneor'';Falseand0count as set, so it can be used for other required keys later. It is called where@storage_deviceis put into the camera config.Why
"storage_device": nullraisedAttributeError: 'NoneType' object has no attribute 'startswith'.KeyError: 'storage_device'.Since #3380 the frontend validation blocks applying a disabled storage option, so the UI does not send
nullanymore, but other clients still can. Found while answering #3380 (comment).Testing
tests/test_storage_device.py:null, empty and missingstorage_deviceare refused, a given device is used, andinput_required()returns'custom-path',Falseand0but refuses a missing key,Noneand''. Against the previousconfig.pythese fail withAttributeError,KeyError,ValueError not raisedand the missinginput_required."storage_device": nullreturns 500, logsERROR: Setting "storage_device" must be set, and leaves the camera config unchanged (storage device and name).ruff check/ruff format --checkpass.🤖 Generated with Claude Code