unslothai/unsloth · error · ValueError
Public preview sharing must be true or false.
Error message
Public preview sharing must be true or false.
What it means
Raised by set_preview_sharing_enabled(value) when _coerce_bool(value) returns None — i.e. the value cannot be interpreted as a boolean. The settings API accepts true/false in several forms but rejects ambiguous values; this guards the persisted PREVIEW_SHARING_SETTING_KEY from garbage. Note the read path (get) never raises — it falls back to the default — only the write path validates.
Source
Thrown at studio/backend/utils/preview_sharing_settings.py:50
A *missing* setting defaults to enabled so the feature keeps working as
before unless an admin explicitly turns it off. A *read failure* (e.g. a
transient SQLite/permission error) fails closed -- this is a kill switch, so
an unreadable settings DB must not silently reopen the public surface.
"""
try:
from storage.studio_db import get_app_setting
stored = get_app_setting(PREVIEW_SHARING_SETTING_KEY, None)
except Exception:
return False
parsed = _coerce_bool(stored)
return parsed if parsed is not None else DEFAULT_PREVIEW_SHARING_ENABLED
def set_preview_sharing_enabled(value: Any) -> bool:
"""Persist whether public ``/p`` preview links are accepted."""
parsed = _coerce_bool(value)
if parsed is None:
raise ValueError("Public preview sharing must be true or false.")
from storage.studio_db import upsert_app_settings
upsert_app_settings({PREVIEW_SHARING_SETTING_KEY: parsed})
return parsed
View on GitHub (pinned to 203007d190)
Solutions
- Send an actual JSON boolean (true/false) from the client for this setting.
- Validate/coerce at the API boundary before calling set_preview_sharing_enabled: reject anything that is not bool, 'true'/'false', or 0/1.
- Return HTTP 400 with the error text so the UI can prompt the user to pick an explicit toggle state.
Example fix
# before
set_preview_sharing_enabled(request.json.get('enabled')) # 'on' -> ValueError
# after
raw = request.json.get('enabled')
if isinstance(raw, str):
raw = raw.strip().lower()
if raw not in (True, False, 'true', 'false', 1, 0):
abort(400, 'Public preview sharing must be true or false.')
set_preview_sharing_enabled(raw) Defensive patterns
Strategy: type-guard
Validate before calling
def to_bool_or_none(v):
if isinstance(v, bool): return v
if isinstance(v, str) and v.strip().lower() in ('true', 'false'):
return v.strip().lower() == 'true'
if v in (0, 1): return bool(v)
return None
parsed = to_bool_or_none(payload.get('enabled'))
if parsed is None:
abort(400, 'Public preview sharing must be true or false.')
set_preview_sharing_enabled(parsed) Type guard
def is_valid_preview_sharing_value(v) -> bool:
return v is True or v is False or (
isinstance(v, str) and v.strip().lower() in ('true', 'false')
) Try / catch
try:
set_preview_sharing_enabled(value)
except ValueError:
abort(400, 'Public preview sharing must be true or false.') # client fix required, no retry Prevention
- Send JSON booleans, not strings, for toggle settings.
- Validate request bodies against a schema (bool type) before hitting settings setters.
When it happens
Trigger: Calling set_preview_sharing_enabled() with values _coerce_bool cannot parse: e.g. 'maybe', 2, [], None (depending on the coercion table), or the string 'yes'/'on' if not in the accepted forms. Typically from a settings API handler passing an unvalidated JSON body field straight through.
Common situations: A frontend settings toggle sending a string like 'on'/'off' instead of true/false, a misconfigured API client, or a test sending arbitrary truthy values. Also a stored DB value that round-trips as a non-boolean type.
Related errors
- Helper LLM startup pre-cache must be true or false.
- OpenAI auto-switch must be true or false.
- Keep KV on idle unload must be true or false.
- Auto-download missing models must be true or false.
- Auto-unload API-loaded only must be true or false.
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/99336eeab4470f67.
Report an issue: GitHub.