Skip to content

fix(utils): keep blank model parameter values instead of raising #1452 - #1453

Merged
ulleo merged 1 commit into
dataease:mainfrom
borealisalastor-byte:fix/1452-blank-model-arg
Nov 10, 2026
Merged

ulleo merged 1 commit into
dataease:mainfrom
borealisalastor-byte:fix/1452-blank-model-arg

Conversation

@borealisalastor-byte

Copy link
Copy Markdown
Contributor

Cause

prepare_model_arg decides whether a value looks like JSON by inspecting the first character of origin_arg.strip():

if not origin_arg.strip()[0] in {'{', '['}:   # empty / whitespace-only -> IndexError

so an empty or whitespace-only value raised IndexError: string index out of range.

get_default_config builds the runtime additional_params from a dict comprehension whose result is wrapped in try/except Exception: pass, so one blank parameter made the whole mapping disappear:

config_raw = [{"key": "temperature", "val": 0}, {"key": "note", "val": ""}, {"key": "max_tokens", "val": 1024}]
runtime additional_params -> {}     # temperature and max_tokens dropped as well

check_llm skips blank values through its own truthiness filter, which is why the crash only shows on the runtime path; which values that filter should keep is tracked separately in #1446.

Fix

  • blank strings are recognised explicitly and returned unchanged, before any index access;
  • non-string inputs (0, False, None, numbers, dicts, lists) keep their current pass-through behaviour;
  • the bare except: next to it becomes except Exception: so a JSON decode error stays contained.

Tests

backend/tests/test_prepare_model_arg.py pins the contract: blank values ("", " ", "\t", "\n") come back unchanged, JSON-looking strings are still parsed, malformed JSON and plain strings stay strings, non-string values keep their identity, and a config carrying one blank parameter keeps its siblings — the last two are exactly the reported failure mode.

Verification

  • python -m pytest -q tests/test_prepare_model_arg.py -> 28 passed after the fix; the same file fails 11 cases against the unmodified source (IndexError in the blank-value cases), run in backend/ on a checkout of main at f10255b;
  • ruff check and ruff format --check pass on the touched files;
  • the full uv run pytest -q suite was not run in the sandbox where the change was prepared, which has no access to the private xpack index.

Fixes #1452

…ease#1452

prepare_model_arg inspected the first character of the stripped value, so an empty or whitespace-only string raised IndexError; get_default_config swallowed the error and dropped every additional parameter of that model configuration. Blank values now pass through unchanged and non-string inputs keep their current behaviour.
@ulleo
ulleo merged commit 0d1a4d3 into dataease:main Nov 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] prepare_model_arg 对空字符串参数抛 IndexError,运行时配置会静默丢弃全部附加参数

2 participants