Possible bug in IF node

Hi,

im kinda new to n8n so im probably overseeing something. anyway, im trying to make a workflow which opens a jira ticket based on emails which are sent to a dedicated inbox. in order to parse the description correctly, i need to do some actions based on the type of the email. i have identified three different types (description in plainText, description in plainText as buffer, description in htmlText as buffer) and want to model these in the workflow with an IF-structure. i tried different configurations of my IF-structure, and the best i came up with is to check for {{$node[“IMAP Email”].json[“textPlain”][“type”]}} is emtpy. but, the thing is: when i execute the whole workflow, it evaluates wrong. when i execute just the node, it evaluates correctly. it seems kinda weird that the node evaluates differently when no parameters are changed. does anyone have similar troubles?
im attaching a snippet of my workflow where i was able to reproduce the issue reliantly. thanks everyone for taking the time to read and help :slight_smile:

Regards,
Michael

Hi @strdl, first of all, welcome to the community! I tried loading your workflow, but it seems there are some formatting issues with it. Could you try using a preformatted block by clicking this button while the cursor is on an empty line:

This should produce nice code ready to be pasted into other n8n instances :slight_smile::

here is where your code goes

Thanks so much!

Hi MutedJam,

thanks for taking the time to review my issue :slight_smile:
i messed up there, seems like i used a quote instead of code block. whoops! i edited the original post, should be good now.

thanks again and have a good day!
Michael

Thanks a lot @strdl! I’m sorry for the trouble this might cause (parsing emails is no fun and unexpected behaviour doesn’t make it any better).

I could now load your workflow and the comparison you are performing in your IF5 node. I gave this a go on my end and the behavior does seem correct to me. My emails wouldn’t include a type field inside the textPlain field text though (as referenced by {{$node["IMAP Email"].json["textPlain"]["type"]}}), so I can’t see any case where this node would evaluate to false.

Could you share an example JSON output from your initial IMAP Email node (without any personal details like email addresses, of course)? Just to get an idea of the data structure you are working with.

Hi @MutedJam !
not your fault parsing emails is a PITA haha. heres the email i was using when reproducing the issue:

[{
	"textHtml": "",
	"textPlain": {
		"type": "Buffer",
		"data": [68, 105, 101, 115, 32, 105, 115, 116, 32, 101, 105, 110, 32, 84, 101, 115, 116, 32, 102, 195, 188, 114, 32, 117, 110, 115, 101, 114, 101, 110, 32, 110, 101, 117, 101, 110, 32, 65, 117, 116, 111, 109, 97, 116, 101, 110, 33, 13, 10, 13, 10, 68, 97, 110, 107, 101, 32, 77, 105, 99, 104, 97, 101, 108, 32, 240, 159, 152, 138, 13, 10, 13, 10, 13, 10, 13, 10, 74, 111, 110, 97, 115, 32, 66, 101, 114, 110, 97, 114, 100, 32, 124, 32, 43, 52, 57, 32, 49, 53, 50, 32, 50, 57, 50, 55, 55, 56, 48, 52, 60, 116, 101, 108, 58, 43, 52, 57, 32, 49, 53, 50, 32, 50, 57, 50, 55, 55, 56, 48, 52, 62, 32, 124, 32, 67, 97, 108, 108, 32, 118, 105, 97, 32, 84, 101, 97, 109, 115, 60, 109, 115, 116, 101, 97, 109, 115, 58, 47, 108, 47, 99, 97, 108, 108, 47, 48, 47, 48, 63, 117, 115, 101, 114, 115, 61, 106, 46, 98, 101, 114, 110, 97, 114, 100, 64, 121, 45, 105, 109, 46, 100, 101, 62, 13, 10]
	},
	"metadata": {
		"mime-version": "1.0",
		"received": "from AM9P194MB1428.EURP194.PROD.OUTLOOK.COM (2603:10a6:20b:3ac::12) by AM7P194MB0756.EURP194.PROD.OUTLOOK.COM with HTTPS; Tue, 11 May 2021 12:18:53 +0000",
		"thread-topic": " deletedSubject",
		"thread-index": "AQHXRl/NI18xH+FEOEOBfl0pRXFUqA==",
		"message-id": "<[email protected]>",
		"accept-language": "de-DE, en-US",
		"content-language": "en-GB",
		"x-ms-exchange-organization-authas": "Internal",
		"x-ms-exchange-organization-authmechanism": "04",
		"x-ms-exchange-organization-authsource": "AM0P194MB0468.EURP194.PROD.OUTLOOK.COM",
		"x-ms-has-attach": "",
		"x-ms-exchange-organization-network-message-id": " 9361e819-7fd2-4026-8673-08d91476f042",
		"x-ms-exchange-organization-scl": "-1",
		"x-ms-tnef-correlator": "",
		"x-ms-exchange-organization-recordreviewcfmtype": "0",
		"x-ms-publictraffictype": "Email",
		"x-microsoft-antispam-mailbox-delivery": " ucf:0;jmr:0;auth:0;dest:I;ENG:(750129)(520011016)(706158)(944506458)(944626604);",
		"x-microsoft-antispam-message-info": " cjK1FjpS9I2SNk2wYJQ0Y0wlpBQyQTLaxxw/hhCeMpaShvcQCbAfiKmQkr2+sPny18sx2j8Alvr3gvvYgZbbCavKMsZBZyM5puB5Wqx+1PzUYzBXYMr/vmI/KWTJx0VRNGWJNa4l3zAmCxCW8nvg32yu57rs2La+cocGIe2+xccKxvktMaI5MkOycbmW3g1+Gfubay+Ni7cInaOZmsHES0hn+CLMj7i7j3dYwmFVrgC9Bcs/FwaM8Pumr5l1wmXnd1T+ctoWcXhgg11FwbaFUmdlOVQfxjSdiUBKI71zG0vnQkzCSVigOVy8G6Wi4xnaI06yJOIqrQ9OjQVFGg83tNJwS3TWa1tcDImvgQNuopGwZAWH6vqcOAU1z1mivo98RYYhatO06Dqs18/IwaX6sxXDkmyZakyAW7B56ayTP8r7irW6VI8iPQSNr2ZNm+teq9q3+XHdKGk7FjLkGIYgcTDNtWNuLVt+sTNXBw1ulBdVPwd7lcUdivUQyZuJsDpichJo4O031dLxExDvu0GpzaeHxSPcxp4VSPK24l1oJmK5lb/SKJFascKyXXAiTPCyH8MRLtA+YIB+Fa+k5Jhtjb4IkHd5JczFsunVpTyhiOJC2chLJwce3dMeYCMY4m8B",
		"content-type": "text/plain; charset="utf-8"",
		"content-id": "<[email protected]>",
		"content-transfer-encoding": "base64"
	},
	"from": "deletedFrom",
	"to": "deletedTo",
	"subject": " deletedSubject",
	"date": "Tue, 11 May 2021 14:18:51 +0200"
}]

i replaced all personal information with “deletedFieldname”, in case something slipped through dont worry, theres no sensible data contained in that mail. now, when i execute the workflow IF5 evaluates to true, but when i execute the IF5 by itself, it evaluates to false (which should be correct to my understanding). is the same happening for you? im on n8n version 0.141.1 btw.

Thanks a lot for your time :slight_smile:
Michael

Thanks so much Michael! My test provider uses a different content type/encoding so the textPlain field would just include human-readable plain text for me. So your example dataset is already super helpful in understanding your data structure.

However, when trying this on my own end running 0.141.1, there was no difference between executing just the IF5 node and the full workflow. What I did notice was that in your expression in the IF5 node you are referencing your initial IMAP Email node ({{$node["IMAP Email"].json["textPlain"]["type"]}}).

So I am wondering if you are possibly fetching more than one email at a time when executing your workflow. The number and order of items might be different at your IF5 node than it is at the IMAP Email node (in case your IF4 node sends items to its true output) meaning this reference could be the culprit.

Does the unexpected behaviour also occur for you when using the input data of the IF5 node through an expression like {{$json["textPlain"]["type"]}} rather than referencing another node?

This is the example workflow I have created to test this:

Example Workflow

Hi @MutedJam ,

thats interesting, i didnt even knew the email provider is involved with the encoding. maybe thats a thing they can fix on their end, im gonna investigate that.

i have a few different test mails that i use for developer tests, but im only using one at a time (like in, theres only 1 email at a time set to unread in my inbox).

i tried to set the expression in my IF5 to

{{$json["textPlain"]["type"]}}

but somehow that expression does not resolve, even if i click it from the side menu → input data where its filled with “Buffer”:

any idea why that might be happening? not sure if its even connected to the original problem, im kind of a beginner with n8n :smiley:

thanks again for your help!
Michael

So the [not found] in the preview would be caused by the data is coming from another IF node. The preview doesn’t like that unfortunately, though it wouldn’t have an impact on actually executing either the node alone or the workflow.

You could put a No Operation node before your IF5 node to get the preview to show up:

Example Workflow
1 Like

Hi @MutedJam ,

good to know, i added a noop as you suggested and now the preview is showing up. however, the issue still persists, when i execute the workflow with the example mail i shared the IF5 evaluates to true, yet textPlain.type is filled with “buffer”:

when i execute the node by itself it evaluates to false:

any ideas what i could try next? thanks again for your help :slight_smile:
Michael

Thanks for confirming @strdl. Is this happening using the example workflow I have posted yesterday?

This would execute to false for me when running the workflow as a whole through the Execute Workflow button (as expected seeing the condition {{$json["textPlain"]["type"]}} Is Empty evaluates to False):

When clicking Execute Node on IF5, the true output is also empty (on version 0.141.1 as well as 0.147.1):

Could you confirm your environment variables/configuration files (again, without any secrets of course) and how you are running n8n (operating system/docker image)? Still not giving up my hope of being able to reproduce this.

Hi @MutedJam ,
sorry for my delayed response, i had a couple of days off work. Ive imported the workflow you provided and in fact, the error is not occuring for your workflow (IF5 evaluates correctly to false, both in workflow and single node execution).
now im asking myself what is the difference between my and your workflow :smiley:
were hosting n8n as a docker container in our microsoft azure environment as far as i know. by

environment variables/configuration files

do you mean the boot configuration for hosting?

Thanks for you help,
Michael

Hi @MutedJam ,

any idea what could be the difference between my and your workflow? i feel like were getting close to finding the root cause here :stuck_out_tongue:

Thanks for you time,
Michael

Sorry @strdl, I am so sorry I forgot to get back to you here. Yes, I meant these guys (and wasn’t sure if you’re using environment variables or configuration files or a mix of both):

Another thing comes to mind was: Is there a chance your workflow runs for more than 1 item at a time (or in other words is your IMAP node receiving multiple emails in a single execution)?

If so, this could cause some unexpected behaviour here as in your IF5 expression you are using {{$node["IMAP Email"].json["textPlain"]["type"]}}. Now, when the IMAP Email node outputs two items, but only the second of these two items reach IF5, this expression would look up the first item from IMAP Email (as it’s the first item received by IF5) and read its textPlain.type field .

So if you have multiple items indeed, you could try replacing the $node expression with the $json expression using the actual input data of the IF5 node to avoid such mixups. You can select this in the expression editor through Current Node → Input Data → JSON:
image