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:
Roland 2026-05-31 12:43:56 -06:00 • committed by lrnselfreliance
parent cd9fb4c6de
commit 9cc5c15e32
8 changed files with 111 additions and 12 deletions

View file

@ -348,6 +348,28 @@ describe('useForm', () => {
expect(typeof result.current.formData.count).toBe('number');
});
it('handleInputEvent preserves decimals for float-friendly number inputs (e.g. sleep_requests)', () => {
const {result} = renderHook(() => useForm({
defaultFormData: {sleep_requests: ''},
submitter: jest.fn(),
}));
act(() => {
result.current.handleInputEvent({
preventDefault: jest.fn(),
target: {
type: 'number',
value: '0.75',
name: 'sleep_requests',
dataset: {},
},
});
});
expect(typeof result.current.formData.sleep_requests).toBe('number');
expect(result.current.formData.sleep_requests).toBe(0.75);
});
it('handleInputEvent uses data-path attribute when available', () => {
const {result} = renderHook(() => useForm({
defaultFormData: {nested: {field: ''}},