{"record":{"id":"2cc3a98068edd41c","repo":"unslothai/unsloth","slug":"auto-download-missing-models-must-be-true-or-false","errorCode":null,"errorMessage":"Auto-download missing models must be true or false.","messagePattern":"Auto-download missing models must be true or false\\.","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"studio/backend/utils/openai_auto_switch_settings.py","lineNumber":321,"sourceCode":"    if media_idle_seconds is not None:\n        parsed_media_idle = _coerce_int(media_idle_seconds)\n        if parsed_media_idle is None:\n            raise ValueError(\"Media auto-unload idle seconds must be a non-negative integer.\")\n        if 0 < parsed_media_idle < MIN_AUTO_UNLOAD_IDLE_SECONDS:\n            raise ValueError(\n                f\"Media auto-unload idle seconds must be 0 (off) or at least \"\n                f\"{MIN_AUTO_UNLOAD_IDLE_SECONDS}.\"\n            )\n    parsed_keep_kv = None\n    if keep_kv is not None:\n        parsed_keep_kv = _coerce_bool(keep_kv)\n        if parsed_keep_kv is None:\n            raise ValueError(\"Keep KV on idle unload must be true or false.\")\n    parsed_auto_download = None\n    if auto_download is not None:\n        parsed_auto_download = _coerce_bool(auto_download)\n        if parsed_auto_download is None:\n            raise ValueError(\"Auto-download missing models must be true or false.\")\n    parsed_api_only = None\n    if api_only is not None:\n        parsed_api_only = _coerce_bool(api_only)\n        if parsed_api_only is None:\n            raise ValueError(\"Auto-unload API-loaded only must be true or false.\")\n    from storage.studio_db import upsert_app_settings\n\n    updates: dict[str, Any] = {OPENAI_AUTO_SWITCH_SETTING_KEY: parsed_enabled}\n    if parsed_idle is not None:\n        updates[AUTO_UNLOAD_IDLE_SETTING_KEY] = parsed_idle\n    if parsed_media_idle is not None:\n        updates[MEDIA_AUTO_UNLOAD_IDLE_SETTING_KEY] = parsed_media_idle\n    if parsed_keep_kv is not None:\n        updates[AUTO_UNLOAD_KEEP_KV_SETTING_KEY] = parsed_keep_kv\n    if parsed_auto_download is not None:\n        updates[OPENAI_AUTO_DOWNLOAD_SETTING_KEY] = parsed_auto_download\n    if parsed_api_only is not None:\n        updates[AUTO_UNLOAD_API_ONLY_SETTING_KEY] = parsed_api_only","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/openai_auto_switch_settings.py#L303-L339","documentation":"Raised by set_openai_auto_switch in openai_auto_switch_settings.py:319-322 when auto_download is provided and cannot be coerced to bool. Same accepted set as other flags: True/False or the strings 1/true/yes/on and 0/false/no/off (trimmed, case-insensitive). Ints other than via those strings, and unknown tokens, are rejected.","triggerScenarios":"set_openai_auto_switch(enabled=True, auto_download=0) — integer zero is rejected even though it 'looks' false. Also auto_download=\"download\", \"y\", or a list.","commonSituations":"Frontend sends 0/1 ints for toggles; YAML/JSON config loaders producing ints; scripting around the settings API with truthy values.","solutions":["Pass bool(auto_download) after your own validation","Send JSON booleans from clients","Map 0/1 to False/True explicitly before calling","Omit the parameter to leave the stored value untouched"],"exampleFix":"# before\nset_openai_auto_switch(enabled=True, auto_download=0)\n\n# after\nset_openai_auto_switch(enabled=True, auto_download=False)","handlingStrategy":"validation","validationCode":"def to_bool(v) -> bool | None:\n    if isinstance(v, bool):\n        return v\n    if isinstance(v, str):\n        n = v.strip().lower()\n        if n in {\"1\", \"true\", \"yes\", \"on\"}: return True\n        if n in {\"0\", \"false\", \"no\", \"off\"}: return False\n    return None\n\nif auto_download is not None and to_bool(auto_download) is None:\n    raise HTTPException(400, \"auto_download must be a boolean\")","typeGuard":"def is_bool_like(v: object) -> bool:\n    return isinstance(v, bool) or (\n        isinstance(v, str) and v.strip().lower() in {\"1\",\"true\",\"yes\",\"on\",\"0\",\"false\",\"no\",\"off\"}\n    )","tryCatchPattern":"try:\n    set_openai_auto_switch(enabled=True, auto_download=auto_download)\nexcept ValueError as exc:\n    raise HTTPException(400, str(exc)) from exc","preventionTips":["Never rely on int 0/1 being accepted — it is not","Keep one shared bool-coercion helper across settings endpoints","Add API schema validation (bool type) for every toggle"],"tags":["settings","validation","boolean-coercion"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}