# N8n v1.91.3 - Nodes (Code/Set) Fail to Output with 0-Item Input Despite 'Always Output Data' / 'Run Once for All Items' - Results in Empty API Response

**URL:** <https://community.n8n.io/t/n8n-v1-91-3-nodes-code-set-fail-to-output-with-0-item-input-despite-always-output-data-run-once-for-all-items-results-in-empty-api-response/116863>\
**Category:** Questions\
**Created:** [Maio 17, 2025, 8:28pm UTC](https://community.n8n.io/t/n8n-v1-91-3-nodes-code-set-fail-to-output-with-0-item-input-despite-always-output-data-run-once-for-all-items-results-in-empty-api-response/116863 "2025-05-17T20:28:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![picturebox1](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/picturebox1/32/78652_2.png) [@picturebox1](https://community.n8n.io/u/picturebox1)\
**Post date:** [Maio 17, 2025, 8:28pm UTC](https://community.n8n.io/t/n8n-v1-91-3-nodes-code-set-fail-to-output-with-0-item-input-despite-always-output-data-run-once-for-all-items-results-in-empty-api-response/116863/1 "2025-05-17T20:28:20Z")

</div>

Hello Again n8n Community,

I’m encountering a different persistent issue with an n8n workflow on version 1.91.3 (self-hosted, Docker on Linode) and would greatly appreciate any insights or known workarounds.

My Goal: I have an API endpoint (Webhook trigger) that checks if a text segment exists in a PostgreSQL database.

If the segment exists, it should respond with `{"status": "ok"}`. (This part works).  
If the segment does NOT exist (Postgres SELECT finds 0 rows), it should insert the segment and respond with `{"status": "created"}`. The problem is that this “not found” path consistently returns an empty string `""` to the HTTP client instead of the desired JSON response.

Core Problem: When my `Postgres SELECT` node outputs 0 items (segment not found), subsequent nodes intended to create a default item (e.g., containing a `found: false` flag) for a downstream `IF` node are failing to produce any output items themselves. This happens even when these “normalizer” nodes are configured with settings that should guarantee an output.

Troubleshooting Steps & Observed Behaviors:

1. `Postgres SELECT` Node:  
This node correctly executes its query.  
When no segment is found, it correctly outputs 0 items.
2. Attempt 1: Using a “Code” Node as a Normalizer:  
Configuration: Placed after `Postgres SELECT`; Mode: “Run Once for All Items”.  
JavaScript was designed to return `[{ json: { found: false, ... } }]` if `($input.all()).length === 0`.  
Symptom: When `Postgres SELECT` outputted 0 items, this Code node also produced 0 output items (n8n UI showed “Execute this node to view data”).  
Debugging: `console.log()` statements at the script’s start did not appear in n8n Docker logs, suggesting the script didn’t execute.
3. Attempt 2: Using a “Set” Node as a Normalizer (Named “CheckIfSegmentFound”):  
Configuration: Placed after `Postgres SELECT`; Settings Tab: “Always Output Data” = ON; Parameters Tab: “Keep Only Set” = ON.  
Test 2a (Dynamic expression): Value `found` = expression `{{ $items("Postgres_Node_Name").length > 0 }}`.  
Symptom: Produced 0 output items (Execution #100).  
Test 2b (Static value): Value `found` = static boolean `false`.  
Symptom: _Still_ produced 0 output items (Execution #102).  
Test 2c (Isolated Set node execution - input disconnected, static value):  
Result: This WORKED. The Set node correctly produced one output item. This suggests “Always Output Data” can function in isolation but fails when triggered by a 0-item input stream from a connected node.
4. Attempt 3: “Merge before Normalize” Strategy (from AI suggestions):

- Structure: `Webhook` & `Postgres (SELECT)` → `MergeInputStreams` node (Mode: Append) → `NormalizeAndCombineData` (Code node) → `IF` node.  
The `NormalizeAndCombineData` (Code node) was set to “Run Once for All Items”. Its JavaScript used `$items("NodeName")` to get data from `Webhook`, `Code1` (my original hash calc node), and `Postgres` (SELECT node). The intended JavaScript is below.  
Symptom (Execution #105): The `Postgres (SELECT)` node itself errored with “Referenced node is unexecuted. An expression references the node ‘Code1’, but it hasn’t been executed yet…” This occurred even though the n8n UI execution path showed “Code1” immediately preceding it and highlighted as green (successfully executed). This specific error prevented full testing of the Merge strategy.

JavaScript for `NormalizeAndCombineData` (Attempt 3):

`JavaScript// — Configuration: Node names used —  
const POSTGRES\_SELECT\_NODE\_NAME = “Postgres”; // Actual name of Postgres SELECT node  
const WEBHOOK\_NODE\_NAME = “Webhook”; // Actual name of Webhook node  
const HASH\_CALC\_NODE\_NAME = “Code1”; // Actual name of hash calculation node (e.g., “Code1”)  
// — End Configuration —

let outputJson = {  
found: false,  
segment\_id: null,  
language\_code: null,  
content: null,  
hash: null,  
debug\_messages:   
};

try {  
outputJson.debug\_messages.push(“NormalizeAndCombineData script started.”);  
console.log(“NormalizeAndCombineData: Script execution started.”);

const pgSelectItems = $items(POSTGRES\_SELECT\_NODE\_NAME);  
const webhookItems = $items(WEBHOOK\_NODE\_NAME);  
const hashCalcItems = $items(HASH\_CALC\_NODE\_NAME);

outputJson.debug\_messages.push(`pgSelectItems count: ${pgSelectItems.length}`);  
outputJson.debug\_messages.push(`webhookItems count: ${webhookItems.length}`);  
outputJson.debug\_messages.push(`hashCalcItems count: ${hashCalcItems.length}`);

if (pgSelectItems.length \> 0 && pgSelectItems[0].json && pgSelectItems[0].json.segment\_id !== undefined) {  
outputJson.found = true;  
outputJson.segment\_id = pgSelectItems[0].json.segment\_id;  
outputJson.debug\_messages.push(`Segment FOUND in DB. ID: ${outputJson.segment_id}`);  
} else {  
outputJson.found = false;  
outputJson.debug\_messages.push(“Segment NOT FOUND in DB by Postgres SELECT.”);  
}

if (webhookItems.length \> 0 && webhookItems[0].json &&  
webhookItems[0].json.body && webhookItems[0].json.body.body) {  
const webhookBodyData = webhookItems[0].json.body.body;  
outputJson.language\_code = webhookBodyData.language\_code;  
outputJson.content = webhookBodyData.content;  
outputJson.debug\_messages.push(`Webhook data retrieved: lang='${outputJson.language_code}', content='${outputJson.content ? outputJson.content.substring(0, 30) + "..." : "null"}'`);  
if (outputJson.language\_code === undefined) outputJson.debug\_messages.push(“Warning: ‘language\_code’ is undefined from Webhook.”);  
if (outputJson.content === undefined) outputJson.debug\_messages.push(“Warning: ‘content’ is undefined from Webhook.”);  
} else {  
outputJson.debug\_messages.push(“ERROR: Webhook data structure error.”);  
console.error(“NormalizeAndCombineData: Webhook data error. webhookItems:”, JSON.stringify(webhookItems));  
}

if (hashCalcItems.length \> 0 && hashCalcItems[0].json && hashCalcItems[0].json.hash !== undefined) {  
outputJson.hash = hashCalcItems[0].json.hash;  
outputJson.debug\_messages.push(`Hash retrieved: ${outputJson.hash}`);  
} else {  
outputJson.debug\_messages.push(“ERROR: Hash data not found from '” + HASH\_CALC\_NODE\_NAME + “'.”);  
console.error(“NormalizeAndCombineData: Hash data error. hashCalcItems:”, JSON.stringify(hashCalcItems));  
}

} catch (error) {  
outputJson.debug\_messages.push(`EXCEPTION: ${error.message}. Stack: ${error.stack}`);  
console.error("NormalizeAndCombineData: EXCEPTION - ", error);  
outputJson.found = outputJson.found || false;  
}

outputJson.debug\_messages.push(“NormalizeAndCombineData script finished.”);  
console.log(“NormalizeAndCombineData: Script finished. Returning:”, JSON.stringify(outputJson));

return [{ json: outputJson }];`

**Summary of Unexplained Behaviors in n8n v1.91.3:**

1. Code Node (“Run Once for All Items”): Appears not to execute its script when direct input is 0 items.
2. Set Node (“Always Output Data: ON”): Fails to output (even static values) when direct input from a connected node is 0 items (though works in isolated test with no input).
3. Node Data Referencing: A node (`Postgres SELECT`) reported its successfully executed direct predecessor (`Code1`) as “unexecuted” (Execution #105).

**Questions for the Community / Support:**

1. Are these known bugs or limitations in n8n v1.91.3?
2. Could environmental factors (Docker, Node.js, `N8N_RUNNERS_ENABLED`) cause this?
3. Besides upgrading, are there other robust workarounds for v1.91.3 to ensure an IF node reliably gets an item if a database query returns 0 rows?
4. Why would a node report its successfully executed predecessor as “unexecuted”?

Any insights for n8n v1.91.3 would be greatly appreciated. This is a critical blocker. Thank you.

---

<div class="post-metadata">

**Author:** ![picturebox1](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/picturebox1/32/78652_2.png) [@picturebox1](https://community.n8n.io/u/picturebox1)\
**Post date:** [Maio 24, 2025, 1:18pm UTC](https://community.n8n.io/t/n8n-v1-91-3-nodes-code-set-fail-to-output-with-0-item-input-despite-always-output-data-run-once-for-all-items-results-in-empty-api-response/116863/2 "2025-05-24T13:18:23Z")

</div>

Quick update: After upgrading to n8n v1.93.0, my initial tests show that a ‘Set’ node (now ‘Edit Fields’) with ‘Always Output Data: ON’ _does_ produce an output item when its input stream has 0 items. This is different from my experience in v1.91.3 where it produced 0 items. I’m now proceeding to test if this resolves my full API ‘false path’ scenario where it should return `{"status": "created"}`. I will update further once that is tested.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [Agosto 22, 2025, 1:18pm UTC](https://community.n8n.io/t/n8n-v1-91-3-nodes-code-set-fail-to-output-with-0-item-input-despite-always-output-data-run-once-for-all-items-results-in-empty-api-response/116863/3 "2025-08-22T13:18:25Z")

</div>

Fechado em Agosto 22, 2025, 1:18pm UTC

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