fix(coderunner): handle null/true/false JSON literals in Python sandbox#2669
Open
octo-patch wants to merge 1 commit intocoze-dev:mainfrom
Open
fix(coderunner): handle null/true/false JSON literals in Python sandbox#2669octo-patch wants to merge 1 commit intocoze-dev:mainfrom
octo-patch wants to merge 1 commit intocoze-dev:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2618
Problem
When a workflow code node parameter has a
nullvalue, the Python sandbox crashes with:Root cause:
json.dumps()serializesnull/Nonevalues as the JSON literalnull, which is then embedded directly into generated Python code via string interpolation:Python does not recognise
null,true, orfalseas keywords — these are JSON literals but not Python identectives. Python usesNone,True, andFalseinstead.Solution
Add
null = None,true = True,false = Falsealiases to the generated code prefix. This ensures that JSON-serialized parameter dicts evaluate correctly when the code string is executed by Pyodide:With these definitions in scope, the generated line
args={"input": "fdsa", "lists": null}is valid Python and evaluatesnullasNone.Testing
Manually verified that a code node with
{"input": "fdsa", "lists": null}input no longer raisesNameError. The aliases are defined before any user code runs, so they do not conflict with user-defined names in themain()function scope.