From 4bfdb1e12373e1c901a54d91968c496941bdf7b0 Mon Sep 17 00:00:00 2001 From: Ricardo-M-L <69202550+Ricardo-M-L@users.noreply.github.com> Date: Thu, 14 May 2026 13:27:04 +0800 Subject: [PATCH] fix: correct nested path traversal in set_variable_param_value (#13986) ## Summary `Graph.set_variable_param_value()` in `agent/canvas.py` has a bug in its nested path traversal logic. The `for` loop iterates through **all** keys in the path (including the last one), descending into every level. After the loop, it then tries to set `cur[keys[-1]] = value`, but `cur` has already descended one level too deep. **Example:** For `path = "a.b"`, `value = "hello"`: - **Before (bug):** `obj["a"]["b"]` becomes `{"b": "hello"}` instead of `"hello"` - **After (fix):** `obj["a"]["b"]` becomes `"hello"` as expected The fix changes `for key in keys:` to `for key in keys[:-1]:`, so the loop only navigates to the parent dict, and the final key is set directly. This is consistent with how the read-side counterpart `get_variable_param_value()` works. This method is called by `set_variable_value()` when assigning to nested variable paths (e.g., `component@root.nested.key`), which is used by the `VariableAssigner` component. ## Test plan - [ ] Create a canvas with a VariableAssigner that writes to a nested path (e.g., `component@obj.nested.key`) - [ ] Verify the value is set correctly at the expected path, not wrapped in an extra dict layer - [ ] Verify single-key paths (e.g., `component@key`) still work correctly ## Summary by CodeRabbit * **Bug Fixes** * Fixed a bug in variable parameter assignment where nested structures were being incorrectly modified, ensuring values are now properly set at their intended locations without unintended overwrites. Co-authored-by: Claude Opus 4.6 (1M context) --- agent/canvas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/canvas.py b/agent/canvas.py index ab6d0ba9ff..bbd06facbb 100644 --- a/agent/canvas.py +++ b/agent/canvas.py @@ -263,7 +263,7 @@ class Graph: keys = path.split('.') if not path: return value - for key in keys: + for key in keys[:-1]: if key not in cur or not isinstance(cur[key], dict): cur[key] = {} cur = cur[key]