Skip to content

fix(config): coerce list/dict/model values in ConfigTool instead of storing raw strings#326

Open
sridhar-3009 wants to merge 1 commit into
HKUDS:mainfrom
sridhar-3009:fix/298-config-tool-type-coercion
Open

fix(config): coerce list/dict/model values in ConfigTool instead of storing raw strings#326
sridhar-3009 wants to merge 1 commit into
HKUDS:mainfrom
sridhar-3009:fix/298-config-tool-type-coercion

Conversation

@sridhar-3009

Copy link
Copy Markdown

Summary

Closes #298

ConfigTool.execute() only coerced bool, int, and float when the
model sent a set action. For list, dict, and nested Pydantic model
fields the raw input string was stored directly via setattr, causing
TypeError or silent misbehavior downstream (e.g. code iterating over
what it expected to be a list, but instead got a string).

New branches added:

Field type Input handling
dict JSON-parsed; non-object payload returns a clear error
list JSON array if input starts with [; otherwise split on commas ("a, b"["a", "b"])
BaseModel subfield JSON-parsed then validated with model_validate()

Example (before):

set web.synthetic_dns_cidrs to "10.0.0.0/8, 192.168.0.0/16"
# stored: "10.0.0.0/8, 192.168.0.0/16"  ← raw string, breaks iteration

Example (after):

set web.synthetic_dns_cidrs to "10.0.0.0/8, 192.168.0.0/16"
# stored: ["10.0.0.0/8", "192.168.0.0/16"]  ← correct list

Test plan

  • set web.synthetic_dns_cidrs to "10.0.0.0/8, 192.168.0.0/16" — verify stored value is ["10.0.0.0/8", "192.168.0.0/16"]
  • set web.synthetic_dns_cidrs to '["10.0.0.0/8"]' (JSON array form) — verify stored value is ["10.0.0.0/8"]
  • set sandbox.docker.extra_env to '{"KEY": "val"}' — verify stored value is {"KEY": "val"}
  • set sandbox.docker.extra_env to an invalid JSON string — verify an error is returned instead of storing raw string
  • Existing bool/int/float coercions continue to work

…toring raw strings

ConfigTool.execute() only coerced bool/int/float when setting a field.
For list, dict, and nested Pydantic model fields the raw input string
was stored directly via setattr, causing TypeError or silent misbehavior
when downstream code tried to iterate over what it expected to be a list.

Add explicit branches for each missing type:
- dict: JSON-parse the input and reject non-object payloads with a clear
  error message.
- list: if the input starts with '[' it is parsed as a JSON array;
  otherwise it is split on commas (e.g. "10.0.0.0/8, 192.168.0.0/16"
  → ["10.0.0.0/8", "192.168.0.0/16"]) for a convenient shorthand.
- BaseModel subfields: JSON-parse and validate via model_validate() so
  nested settings blocks (e.g. sandbox, web) can be set atomically.

Fixes HKUDS#298
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]: ConfigTool silently stores raw strings for list/dict/nested settings fields

1 participant