Switch unexpected behaviour

Hello,

I encountered an unexpected behaviour (bug?) with a switch. I’m routing 19 items towards it, however it only processes around 12 of those items, since I have enabled the fallback option, even if none of the cases were true all items should be accounted for. How come a third of my items get lost/aren’t processed?

Information on your n8n setup

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

Is the fallback option a specific condition ? All i could think of is your fallback condition never met, did you try putting as fallback “item exists” (or maybe you do this already) ?

The fallback is the “extra Output” option, according to the ? next to it, this should be a catch-all for everything that doesn’t fit the other cases and result in the items appearing in the fallback branch of the output.
I don’t have any specific condition tied to the fallback (I don’t know if that is even possible).

Quick question: why do you shortcircuit the Loop node?

Are there any nodes past Switch that return no data? This may lead to early termination of the workflow. Upd: tested. Not the case.

It would better if you could paste the actual workflow here using </> button. Ideally of you could also pin data in the node right before Loop.

This might help to pinpoint the issue.

How do I get the code to paste in with </>?
It’s a rather big workflow so I’d prefer to only paste in the relevant part.

On your workflow canvas select nodes you want to copy and Ctrl/Cmd-C them.

You may want to pin some data in critical nodes before copying the workflow.

In forum reply to any relevant post, click the </> button in editor menu. It will create a pair of triple backticks with a tip. Replace the tip with clipboard content (Ctrl/Cmd-V).

Something is definitely wrong past Switch node.
You should look for the logical flow stops mid-way when a node doesn’t produce any output.

Example:

Here I made the Code node to return no data and this breaks the flow.
So you need to look for something like this. Note that since each of the branches run multiple times in your scenario, the breaking node may not be that obvious. It will just have less runs than expected.

Another thing is that Loop needs all branches that stem from it be wired back to it to work properly and make debugging easier.

Here is an example of a properly set up Loop:

NB. This is my yesterday’s attempt to reproduce your case. The Switch conditions are different as I didn’t have a chance to look behind the scenes of your actual set up at the time being.
But it doesn’t matter for the purpose.

Note that it works.

Now I deliberately introduce a logical error into one of the nodes.
Note that now very few items are actually processed and how easy it is to spot where the flow breaks.

You need to look for something like this in your actual workflow. Again, a failing node may fail not at its first run.

Hope the above helps. If it does help you to spot the issue and resolve it, please mark this post as a :white_check_mark: Solution.

1 Like

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