The JS code doesn't work, but Python does
Self Checks
- [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [X] I have searched for existing issues search for existing issues, including closed ones.
- [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
- [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
- [X] Please do not modify this template :) and fill in all the required fields.
Dify version
0.14.2
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
Write two loop bodies using JS and Python respectively, the JS version produces an empty result, but the Python version works normally.
JS
function main(inputStr, maxRecursionTimes) {
let tmpRecursionList = [];
console.debug(inputStr,maxRecursionTimes)
for (let i = 0; i < maxRecursionTimes; i++) {
tmpRecursionList.push(inputStr);
}
return {
result: tmpRecursionList
};
}
Python
def main(inputStr: str, maxRecursionTimes: int) -> dict:
tmpRecursionList = []
for i in range(maxRecursionTimes):
tmpRecursionList.append(inputStr)
return {'result': tmpRecursionList}
✔️ Expected Behavior
The result data of the JS version should be output normally
❌ Actual Behavior
JS version produces an empty result
@Charlieyurong Hello there! I'm here to help you with any bugs, questions, or contributions while we wait for a human maintainer. I'm looking forward to assisting you!
The issue you're experiencing with the JavaScript code not producing the expected result might be related to the execution environment or specific configurations in the Dify platform. Here are a few things to consider:
-
Execution Environment: Ensure that the JavaScript code is running in the correct execution environment. Dify uses a sandboxed environment for executing JavaScript and Python code, which might have specific restrictions or configurations that affect execution [1].
-
Debugging: Add more debugging statements to check if the loop is being executed as expected. For example, you can log the value of
iinside the loop to see if it iterates correctly. -
Dependencies: Verify if there are any missing dependencies or configurations required for JavaScript execution. While Python dependencies are automatically managed, JavaScript might require manual configuration [2].
-
Error Handling: Check if there are any errors or exceptions being thrown that might not be visible. Dify provides mechanisms for error handling and retrying code execution, which might help in diagnosing the issue [3].
If these steps do not resolve the issue, it might be helpful to compare the execution context or any specific settings that might differ between JavaScript and Python in your setup.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other
Did you run it on mac m series?
Did you run it on mac m series?
no,i run it on docker desktop
Did you run it on mac m series? i have same problem on mac m series and i have error "operation not permitted", you know how to solve it ?
Did you run it on mac m series? i have same problem on mac m series, do you know how to solve it
yes I know how to solve it but I do not know the root cause my guess is GitHub Actions build problem
steps:
- install a virtual machine on your mac( I use orbstack https://orbstack.dev/)
- build the sandbox in the virtual machine -> https://github.com/langgenius/dify-sandbox (build the docker image)
- delete the sandbox image(container) in your machine
- copy the docker image to your mac m machine(docker export -> docker load)
It's a little complicated. but can work in your mac
cc @Yeuoly
Input parameters need to be braces. Without parentheses, my test results are also empty.
Hi, @Charlieyurong. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.
Issue Summary:
- The issue involved a JavaScript function not populating a list correctly, unlike its Python counterpart.
- Suggested solutions included checking the execution environment and adding debugging statements.
- Discussions highlighted related issues on Mac M series, with a workaround using a virtual machine.
- The problem was resolved by enclosing input parameters in braces, as noted by @jiandanfeng.
Next Steps:
- Please confirm if this issue is still relevant to the latest version of the Dify repository. If so, you can keep the discussion open by commenting here.
- If there are no further updates, this issue will be automatically closed in 15 days.
Thank you for your understanding and contribution!