mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-29 03:16:22 -05:00
fix: coerce sleep_requests and numeric settings from string form values
`sleep_requests` (and other numeric inheritable video download settings)
could arrive as strings ('' or '0.75') from the frontend NumberInputForm
and DownloadRequest bodies. These were persisted into Download.settings
(JSONB) and later triggered:
if effective['sleep_requests'] > 0:
TypeError: '>' not supported between instances of 'str' and 'int'
in VideoDownloader.execute_download (and similar sites).
Root cause: DownloadSettings.__post_init__ only filtered None/[] and did
no type coercion, even though the dataclass declared Optional[float]/int.
Changes (minimal targeted fix):
- Add _coerce_optional_number helper and apply it to all numeric fields
in DownloadSettings.__post_init__ (the existing sanitization boundary).
- Centralize legacy string coercion for persisted data in the single
read chokepoint: get_effective_video_settings.
- Simplify VideoDownloaderConfig.sleep_requests getter.
- Frontend: use parseFloat for type=number inputs + null defaults for
sleep_requests (prevents '' from ever being submitted).
- Add focused regression test for string coercion path.
- Revert unrelated change to string field filtering behavior.
No NaN/Inf speculation, no duplicated try/float guards at every call site,
no behavior change for non-numeric settings.
This commit is contained in:
parent
cd9fb4c6de
commit
9cc5c15e32
8 changed files with 111 additions and 12 deletions
|
|
@ -151,7 +151,11 @@ export function useForm({
|
|||
let {path} = e.target.dataset;
|
||||
path = path || e.target.name;
|
||||
if (type === 'number' && !isNaN(value)) {
|
||||
value = parseInt(value);
|
||||
// Use parseFloat (not parseInt) so decimal values (sleep_requests=0.75, durations, etc.)
|
||||
// coming from <input type="number" step="0.25"> are preserved as floats.
|
||||
// This fixes the TypeError when those values later reach Python's > 0 comparison.
|
||||
// Whole numbers (e.g. 42) remain proper numbers.
|
||||
value = parseFloat(value);
|
||||
}
|
||||
console.debug('handleInputEvent', 'path=', path, 'type=', type, 'value=', value);
|
||||
|
||||
|
|
@ -365,7 +369,7 @@ export function NumberInputForm({
|
|||
}) {
|
||||
// Default to positive number.
|
||||
validator = validator || ((value) => {
|
||||
value = _.isNumber(value) ? value : parseInt(value);
|
||||
value = _.isNumber(value) ? value : parseFloat(value);
|
||||
if (value < 0) {
|
||||
return 'Number must be positive'
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue