When I use a code node in my workflow, that code node is not executing my code what I kept inside. Instead of that it is simply returning the previous node input as output. How I need to resolve this?

when I use a code node in my workflow, that code node is not executing my code what I kept inside. Instead of that it is simply returning the previous node input as output. How I need to resolve this ?

[

{

“error”: “The connection cannot be established, this usually occurs due to an incorrect host (domain) value”

}

]
this is the input I am receiving from my previous node and I’m kept the below code for code node
from datetime import datetime

workflow_id_val = “{workflow_id}”
results =

for item in items:
try:

Get input JSON

input_data = item.get(“json”, {})

    # Determine exit code
    exit_code = 0
    stderr = None
    if 'error' in input_data and input_data['error']:
        exit_code = 1
        stderr = input_data['error']
    elif 'stderr' in input_data and input_data['stderr']:
        exit_code = 1
        stderr = input_data['stderr']
    elif 'exitCode' in input_data and input_data['exitCode'] != 0:
        exit_code = input_data['exitCode']
        stderr = input_data.get('stderr', 'Command failed with non-zero exit code')

    # ⚡ Force overwrite all output fields
    result = {
        'dag_id': workflow_id_val,
        'status': 'success' if exit_code == 0 else 'failed',
        'last_run_time': datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'),
        'error': stderr
    }

except Exception as e:
    result = {
        'dag_id': workflow_id_val,
        'status': 'failed',
        'last_run_time': datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'),
        'error': f'Exception: {str(e)}',
        'debug_items': str(items)
    }

# Always return result only — do not merge with old input
results.append({"json": result})

return results
now this code node has to return the json structure what I am returning but instead of that it is returning the previous node input
[
{
“error”: “The connection cannot be established, this usually occurs due to an incorrect host (domain) value”,
“myNewField”: 1
}
]
I’m thinking it is not executing my code so what could be the reason for this and how I can resolve ?

Describe the problem/error/question

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

In n8n the Code node only runs JavaScript, not Python.

So your snippet isn’t executing at all, which is why you just see the previous node’s input passed through. To fix it you’ll need to rewrite your logic in JavaScript/TypeScript inside the Code node.

If you really need Python, you’d have to call it via the Python node (community package) or execute it externally with the Execute Command node.
Read for more info : Python (Pyodide - legacy)

This is incorrect

Can you please share your workflow?

Can you please look into this…I corrected the issue that only js will execute not python after that now I’m facing this.

Hello,

The problem happens because in the Code node only one language executes at a time (either JS or Python). Since the node is set to language: "python", the jsCode section will not run, so $parameter.workflow_id never resolves inside JS.

:white_check_mark: Fix:

  • If you want to access workflow_id in JS, change language to "javaScript".

  • Or, if you want to use Python only, pass workflow_id as an input field (via item.json or $json.workflow_id) instead of $parameter.

This way, the correct language executes and workflow_id will be accessible.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.