Skip to content

fix(coderunner): handle null/true/false JSON literals in Python sandbox#2669

Open
octo-patch wants to merge 1 commit intocoze-dev:mainfrom
octo-patch:fix/issue-2618-null-param-in-code-node
Open

fix(coderunner): handle null/true/false JSON literals in Python sandbox#2669
octo-patch wants to merge 1 commit intocoze-dev:mainfrom
octo-patch:fix/issue-2618-null-param-in-code-node

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #2618

Problem

When a workflow code node parameter has a null value, the Python sandbox crashes with:

NameError: name 'null' is not defined

Root cause: json.dumps() serializes null/None values as the JSON literal null, which is then embedded directly into generated Python code via string interpolation:

code = prefix + f'args={json.dumps(params)}\n' + user_code + suffix
# produces: args={"input": "fdsa", "lists": null}

Python does not recognise null, true, or false as keywords — these are JSON literals but not Python identectives. Python uses None, True, and False instead.

Solution

Add null = None, true = True, false = False aliases to the generated code prefix. This ensures that JSON-serialized parameter dicts evaluate correctly when the code string is executed by Pyodide:

null = None
true = True
false = False

With these definitions in scope, the generated line args={"input": "fdsa", "lists": null} is valid Python and evaluates null as None.

Testing

Manually verified that a code node with {"input": "fdsa", "lists": null} input no longer raises NameError. The aliases are defined before any user code runs, so they do not conflict with user-defined names in the main() function scope.

When a workflow code node receives a parameter with a null value, the
Python sandbox crashes with NameError: name 'null' is not defined.

Root cause: json.dumps() serializes Python/Go nil values as JSON literal
'null', which is then embedded directly into generated Python code. But
Python does not recognise 'null' (or 'true'/'false') as keywords.

Fix: add `null = None`, `true = True`, `false = False` to the generated
code prefix so that JSON-serialized parameter dicts evaluate correctly
as Python literals.

Fixes coze-dev#2618
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.

代码节点输入参数有null后报错

1 participant