Complete & Split: is the value wrong?

Hi There,

and sorry to go with this complete node topic but ....

[{"id":"801126629e8ab7c2","type":"inject","z":"14ef36ad590a7fe8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,2,3,4]","payloadType":"json","x":540,"y":740,"wires":[["43e9c21fa8e74c31"]]},{"id":"50914d4efa31df6e","type":"complete","z":"14ef36ad590a7fe8","name":"","scope":["43e9c21fa8e74c31"],"uncaught":false,"x":1008,"y":495,"wires":[["fa1a47e2ee058fb1"]]},{"id":"fa1a47e2ee058fb1","type":"debug","z":"14ef36ad590a7fe8","name":"debug 394","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"counter","x":1350,"y":336,"wires":[]},{"id":"3ed5963b7a8e8f57","type":"join","z":"14ef36ad590a7fe8","name":"","mode":"custom","build":"array","property":"","propertyType":"full","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1014,"y":740,"wires":[["ef44b9d6ea93685b"]]},{"id":"43e9c21fa8e74c31","type":"split","z":"14ef36ad590a7fe8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":792,"y":605,"wires":[["3ed5963b7a8e8f57"]]},{"id":"ef44b9d6ea93685b","type":"debug","z":"14ef36ad590a7fe8","name":"debug 395","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"counter","x":1322,"y":588,"wires":[]}]

This time the complete is listening to the split node which receives a message with [1,2,3,4] array of four values. It sends out four messages to the join. It also sends a message to the complete node but instead of sending the original array, it sends the value '4' i.e. the last value in the array:

Shouldn't that be the content of the original message, i.e. [1,2,3,4] since that's the message with which the split has completed with?

hmm - possibly/probably yes. The idea of the complete node was to aid transactionality of flows - so that if either something broke halfway through or if a flow was asked to stop then you could possibly how far it had got and take steps to recover from that point... BUT that gets tricky around these case where a node does more than one thing... when is it really complete ? and indeed there are no doubt some inconsistencies in the existing implementations that could be thought through a bit more.

In this specific case I would need to check if it was sending 4 for the last item value or 4 for the number of items processed...

1 Like

I added ten to the list and got 10 as complete message ... :wink:

EDIT: I didn't add ten elements just the number 10 :wink:

1 Like

yes - I see that - net is that I think I agree with you that in this case the complete node should really send the original input payload. I can raise a PR - but need to check with @knolleary where we raise it as it is a potentially breaking change (for someone).

4 Likes

This edge case has a finer edge to it than any good Japanese Samurai sword ...

... and then the world bank collapses because they were checking the last value in an array.

Even using a Complete node with a Split would be a very unusual thing to do I think. It is mostly of use with async nodes.

Not if you had a query that returned an array of financial trades for example. You would want to split and track progress of each one.

folks do strange things and in particular banks.

I could well imagine someone asking how to get the last value of an array in a visual fbp way ... well if we send the array to the split and then have a complete node listening to it we get the last value - 10 points for creativity, 0 for correctness!

EDIT: I'm definitely not questioning the usefulness of the complete node, just that one use case with split ....

Having worked in a couple of large UK banks on their IT, mostly there are only a couple of people in the bank who actually know how the financial processing actually works! :slight_smile: And those people are not financial people! I several times found myself with more knowledge than bank staff simply because I'd done some homework.

Pull request raised Let split node send original msg to complete node by dceejay · Pull Request #5113 · node-red/node-red · GitHub

Btw I found the same issue with the status node - it filters direct nodes from which it will ignore status updates but if I put a change in-between the status and the node producing the status update, I've got an endless loop.

I.e. this setup:

If I enable the change node and then trigger one of the injects, loop is created. Especially since the status is ever changing in the debug node 398 - it's a message counter, status each time now, status all sends out message, debug 398 counts that message, new status, status all captchas that status update and sends out a message, debug 398 counts that message, updates its status, status all captchas that update .... and I'm dizzy.

1 Like

Good shout - will apply same "simple" fix to status node.