Sub workflow works independently but not in main workflow

Describe the problem/error/question

The sub workflow works fine when run independently, but when run through the main workflow it errors. The sub workflow is designed to be independent of the main workflow and only relies on an id being passed in, all of the state information is read from a postgres database. Skipping previous sub workflow executions does not solve the issue.

What is the error message (if any)?

Paired item data for item from node ‘Get Sections for Backgrounds’ is unavailable. Ensure ‘Get Sections for Backgrounds’ is providing the required output.

Please share your workflow

{

“nodes”: [{“parameters”: {},“type”: “n8n-nodes-base.manualTrigger”,“typeVersion”: 1,“position”: [0,0],“id”: “ffe1ded0-5431-4121-ae4c-7d71297307e6”,“name”: “When clicking ‘Execute workflow’”},{“parameters”: {“inputSource”: “passthrough”},“type”: “n8n-nodes-base.executeWorkflowTrigger”,“typeVersion”: 1.1,“position”: [0,144],“id”: “1c6be813-873a-4a7f-a4ea-3706b7b7102b”,“name”: “When Executed by Another Workflow”},{“parameters”: {“jsCode”: “var context = $input.first().json.context;\nvar ctr = 0;\nfor (var i=0; i<context.sections.length; i++) {\n  if (context.sections[i].hasOwnProperty(“background_image”) && context.sections[i].background_image !== “”) {\n    ctr++;\n  }\n}\n\nfor (const item of $input.all()) {\n  item.json.run = ctr !== context.sections.length;\n}\n\n\n\nreturn $input.all();”},“type”: “n8n-nodes-base.code”,“typeVersion”: 2,“position”: [432,64],“id”: “a9016331-006f-4069-bee4-2cff1f70c4c1”,“name”: “Create Context”},{“parameters”: {“conditions”: {“options”: {“caseSensitive”: true,“leftValue”: “”,“typeValidation”: “strict”,“version”: 2},“conditions”: [{“id”: “6944cb5d-f271-454b-a625-e8f751c762b0”,“leftValue”: “={{ $json.run }}”,“rightValue”: “”,“operator”: {“type”: “boolean”,“operation”: “true”,“singleValue”: true}}],“combinator”: “and”},“options”: {}},“type”: “n8n-nodes-base.if”,“typeVersion”: 2.2,“position”: [640,64],“id”: “aa3633a8-65d7-47c0-8879-88f6e380840b”,“name”: “If”,“alwaysOutputData”: false},{“parameters”: {“operation”: “select”,“schema”: {“__rl”: true,“mode”: “list”,“value”: “public”},“table”: {“__rl”: true,“value”: “courses”,“mode”: “list”,“cachedResultName”: “courses”},“limit”: 1,“where”: {“values”: [{“column”: “status”,“value”: “=in progress”}]},“options”: {}},“type”: “n8n-nodes-base.postgres”,“typeVersion”: 2.6,“position”: [224,64],“id”: “30c7306a-7fb5-4424-9232-8e166a32b322”,“name”: “get course”,“credentials”: {“postgres”: {“id”: “Dut2I3pmKHRQWjVg”,“name”: “Postgres account”}}},{“parameters”: {“command”: “=curl -X POST http://172.17.0.1:9003/oneapi/v1/execute -d ‘{“wait_for_result”:true,“timeout”:3000000,“workflow”:{“1”:{“inputs”:{“vae_name”:“qwen_image_vae.safetensors”},“class_type”:“VAELoader”,“_meta”:{“title”:“Load VAE”}},“2”:{“inputs”:{“clip_name”:“qwen_2.5_vl_7b_fp8_scaled.safetensors”,“type”:“qwen_image”,“device”:“cpu”},“class_type”:“CLIPLoader”,“_meta”:{“title”:“Load CLIP”}},“3”:{“inputs”:{“text”:“”,“clip”:[“2”,0]},“class_type”:“CLIPTextEncode”,“_meta”:{“title”:“CLIP Text Encode (Negative Prompt)”}},“4”:{“inputs”:{“samples”:[“7”,0],“vae”:[“1”,0]},“class_type”:“VAEDecode”,“_meta”:{“title”:“VAE Decode”}},“5”:{“inputs”:{“unet_name”:“qwen_image_distill_full_fp8_e4m3fn.safetensors”,“weight_dtype”:“default”},“class_type”:“UNETLoader”,“_meta”:{“title”:“Load Diffusion Model”}},“6”:{“inputs”:{“shift”:3.0000000000000004,“model”:[“5”,0]},“class_type”:“ModelSamplingAuraFlow”,“_meta”:{“title”:“ModelSamplingAuraFlow”}},“7”:{“inputs”:{“seed”:170257094209252,“steps”:10,“cfg”:1,“sampler_name”:“res_multistep”,“scheduler”:“simple”,“denoise”:1,“model”:[“6”,0],“positive”:[“13”,0],“negative”:[“3”,0],“latent_image”:[“8”,0]},“class_type”:“KSampler”,“_meta”:{“title”:“KSampler”}},“8”:{“inputs”:{“width”:1328,“height”:747,“batch_size”:1},“class_type”:“EmptySD3LatentImage”,“_meta”:{“title”:“EmptySD3LatentImage”}},“9”:{“inputs”:{“filename_prefix”:“ComfyUI”,“images”:[“4”,0]},“class_type”:“SaveImage”,“_meta”:{“title”:“Save Image”}},“13”:{“inputs”:{“text”:“{{ $json.image_prompt }}”,“clip”:[“2”,0]},“class_type”:“CLIPTextEncode”,“_meta”:{“title”:“CLIP Text Encode (Positive Prompt)”}}}}’”},“type”: “n8n-nodes-base.executeCommand”,“typeVersion”: 1,“position”: [1728,144],“id”: “e4d4edd1-a0c1-4d0f-9a1a-1dece058e57a”,“name”: “Generate Image1”,“alwaysOutputData”: true},{“parameters”: {“command”: “sh /comfyui/data/wan-render/scripts/get_last_file.sh /comfyui/data/wan-render/output\n”},“type”: “n8n-nodes-base.executeCommand”,“typeVersion”: 1,“position”: [1888,144],“id”: “95128acf-337c-4356-8501-d2b55dd3245d”,“name”: “Get Last Modified File”},{“parameters”: {“jsCode”: “// Loop over input items and add a new field called ‘myNewField’ to the JSON of each one\nvar idx;\nfor (var i=0; i<$(‘Create Context’).first().json.context.sections.length; i++) {\n  if ($(‘Create Context’).first().json.context.sections[i].topic == $(‘Loop Over Items’).first().json.topic) {\n    idx = i;\n    break;\n  }\n} \n\n$(‘Create Context’).first().json.context.sections[idx].background_image = background_${idx}.png;\nfor (const item of $input.all()) {\n  item.json.filename = $input.first().json.stdout.split(" “).pop();\n}\nreturn $input.all();”},“type”: “n8n-nodes-base.code”,“typeVersion”: 2,“position”: [2080,144],“id”: “83282bc5-54d9-45d5-bed3-58ffa0b22eb2”,“name”: “get filename”},{“parameters”: {“options”: {}},“type”: “n8n-nodes-base.splitInBatches”,“typeVersion”: 3,“position”: [1280,48],“id”: “1a0481f0-2a62-4910-ada9-944298c17b3c”,“name”: “Loop Over Items”},{“parameters”: {“operation”: “update”,“schema”: {“__rl”: true,“mode”: “list”,“value”: “public”},“table”: {“__rl”: true,“value”: “=courses”,“mode”: “name”},“columns”: {“mappingMode”: “defineBelow”,“value”: {“id”: “={{ $(‘get course’).item.json.id }}”,“context”: “={{ $(‘Create Context’).item.json.context }}”},“matchingColumns”: [“id”],“schema”: [{“id”: “id”,“displayName”: “id”,“required”: false,“defaultMatch”: true,“display”: true,“type”: “string”,“canBeUsedToMatch”: true,“removed”: false},{“id”: “title”,“displayName”: “title”,“required”: true,“defaultMatch”: false,“display”: true,“type”: “string”,“canBeUsedToMatch”: true,“removed”: true},{“id”: “created_at”,“displayName”: “created_at”,“required”: false,“defaultMatch”: false,“display”: true,“type”: “dateTime”,“canBeUsedToMatch”: true,“removed”: true},{“id”: “modified_at”,“displayName”: “modified_at”,“required”: false,“defaultMatch”: false,“display”: true,“type”: “dateTime”,“canBeUsedToMatch”: true,“removed”: true},{“id”: “prompts”,“displayName”: “prompts”,“required”: false,“defaultMatch”: false,“display”: true,“type”: “object”,“canBeUsedToMatch”: true,“removed”: true},{“id”: “article”,“displayName”: “article”,“required”: false,“defaultMatch”: false,“display”: true,“type”: “string”,“canBeUsedToMatch”: true,“removed”: true},{“id”: “screenplay”,“displayName”: “screenplay”,“required”: false,“defaultMatch”: false,“display”: true,“type”: “object”,“canBeUsedToMatch”: true,“removed”: true},{“id”: “status”,“displayName”: “status”,“required”: false,“defaultMatch”: false,“display”: true,“type”: “string”,“canBeUsedToMatch”: true,“removed”: true},{“id”: “system_prompts”,“displayName”: “system_prompts”,“required”: false,“defaultMatch”: false,“display”: true,“type”: “object”,“canBeUsedToMatch”: true,“removed”: true},{“id”: “context”,“displayName”: “context”,“required”: false,“defaultMatch”: false,“display”: true,“type”: “object”,“canBeUsedToMatch”: true},{“id”: “steps”,“displayName”: “steps”,“required”: false,“defaultMatch”: false,“display”: true,“type”: “object”,“canBeUsedToMatch”: true,“removed”: true}],“attemptToConvertTypes”: false,“convertFieldsToString”: false},“options”: {}},“type”: “n8n-nodes-base.postgres”,“typeVersion”: 2.6,“position”: [1696,-48],“id”: “dd0a4c31-b67a-4ec0-89a5-77b28e4d5ffd”,“name”: “Update rows in a table”,“credentials”: {“postgres”: {“id”: “Dut2I3pmKHRQWjVg”,“name”: “Postgres account”}}},{“parameters”: {“jsCode”: “// Loop over input items and add a new field called ‘myNewField’ to the JSON of each one\nvar text = $input.first().json.image_prompt.replaceAll(”*“, “”).replaceAll(”\n", “”).replaceAll(‘“’, “”).replaceAll(”(“, “”).replaceAll(”)“, “”).replaceAll(”-“, “”).replaceAll(”{“,”“).replaceAll(”}“,”“).replaceAll(”[“,”“).replaceAll(”]“,”“).replaceAll(”&“, “and”).replaceAll(”'", “”);\n\nfor (const item of $input.all()) {\n  $input.first().json.image_prompt = text;\n}\n\nreturn $input.all();”},“type”: “n8n-nodes-base.code”,“typeVersion”: 2,“position”: [1552,144],“id”: “bb6fd793-c51c-46f9-8da1-a582425a1010”,“name”: “Sanitize Prompt”},{“parameters”: {“command”: “=mv /comfyui/data/wan-render/output/{{ $json.filename }} /tmp/{{ $(‘get course’).item.json.id }}/backgrounds”},“type”: “n8n-nodes-base.executeCommand”,“typeVersion”: 1,“position”: [2272,144],“id”: “94e3b9fb-5fa3-4a21-a621-b80d2a3b9a63”,“name”: “Execute Command”},{“parameters”: {“jsCode”: “// Loop over input items and add a new field called ‘myNewField’ to the JSON of each one\nreturn $input.first().json.context.sections;”},“type”: “n8n-nodes-base.code”,“typeVersion”: 2,“position”: [960,48],“id”: “05e6345c-4fa9-45d5-b4f3-6c14ba6e66a7”,“name”: “Get Sections for Backgrounds”}],“connections”: {“When clicking ‘Execute workflow’”: {“main”: [[{“node”: “get course”,“type”: “main”,“index”: 0}]]},“When Executed by Another Workflow”: {“main”: [[{“node”: “get course”,“type”: “main”,“index”: 0}]]},“Create Context”: {“main”: [[{“node”: “If”,“type”: “main”,“index”: 0}]]},“If”: {“main”: [[{“node”: “Get Sections for Backgrounds”,“type”: “main”,“index”: 0}],]},“get course”: {“main”: [[{“node”: “Create Context”,“type”: “main”,“index”: 0}]]},“Generate Image1”: {“main”: [[{“node”: “Get Last Modified File”,“type”: “main”,“index”: 0}]]},“Get Last Modified File”: {“main”: [[{“node”: “get filename”,“type”: “main”,“index”: 0}]]},“get filename”: {“main”: [[{“node”: “Execute Command”,“type”: “main”,“index”: 0}]]},“Loop Over Items”: {“main”: [[{“node”: “Update rows in a table”,“type”: “main”,“index”: 0}],[{“node”: “Sanitize Prompt”,“type”: “main”,“index”: 0}]]},“Sanitize Prompt”: {“main”: [[{“node”: “Generate Image1”,“type”: “main”,“index”: 0}]]},“Execute Command”: {“main”: [[{“node”: “Loop Over Items”,“type”: “main”,“index”: 0}]]},“Get Sections for Backgrounds”: {“main”: [[{“node”: “Loop Over Items”,“type”: “main”,“index”: 0}]]}},“pinData”: {“When clicking ‘Execute workflow’”: [{“id”: “413b3984-3c50-4237-b978-32025752d984”}]},“meta”: {“templateCredsSetupCompleted”: true,“instanceId”: “0827f426dfbd5c34be47b213127a9fdbd813cf5a0b0156e09a0a6d8093167da4”}}

Share the output returned by the last node

Paired item data for item from node ‘Get Sections for Backgrounds’ is unavailable. Ensure ‘Get Sections for Backgrounds’ is providing the required output.

Information on your n8n setup

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

Hi @Matt_Marchio ,

Please share your workflow in a code block else we are unable to use the formated json in your post

Updated @Wouter_Nigrini

You need to copy it from n8n again. The json is still formatted if you copied it from here

re copied it and it doesn’t look like it made much of a difference.

updated to 2.2.4, issue still persists.

Please can you share your workflow in a new post here so we can have a look