_msgid being saved to object in context

I have a simple inject->function flow to recreate an object in the flow context for when I mess it up in my other flows. For some reason, it saves a _msgid to that object. It's the same _msgid as the function node automatically adds when passing to the next debug node. I have to add a change node to delete it. Is this just on my system?

[{"id":"4e3642eb.1c771c","type":"inject","z":"893c9b3d.b9d948","name":"","topic":"","payload":"","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":440,"wires":[["3adbd3d0.43b54c","f8562bc.8e668d8"]]},{"id":"3adbd3d0.43b54c","type":"function","z":"893c9b3d.b9d948","name":"create default fans context object","func":"var fanList = ['5700SmallFans', '11kFan', '6500Fan', 'e4kFan'];\nvar fans = {};\n\nfor (let index in fanList){\n    fans[fanList[index]] = {};\n    fans[fanList[index]].deviceName = fanList[index];\n    fans[fanList[index]].autoEnabled = 0;\n    fans[fanList[index]].autoMode = 0;\n    fans[fanList[index]].autoModeDesc = \"cooling\";\n    fans[fanList[index]].autoTemp = 15;\n    fans[fanList[index]].autoRun = 0;\n}\n\nflow.set('fans', fans);\nnode.warn(fans);\n\nreturn fans;","outputs":1,"noerr":0,"x":320,"y":440,"wires":[["5160fe8a.54c47"]]},{"id":"5160fe8a.54c47","type":"debug","z":"893c9b3d.b9d948","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":530,"y":440,"wires":[]},{"id":"f8562bc.8e668d8","type":"change","z":"893c9b3d.b9d948","name":"","rules":[{"t":"delete","p":"fans._msgid","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":480,"wires":[[]]}]

Returning null from my function node fixes it, but I still don't understand how it gets saved to the flow context.

flow.set('fans', fans);
node.warn(fans);

return fans;

This places the fans object into Context. You then return a reference to the same object to the next node. That message gets an id assigned to it - but as it is a reference to the object you have put into context, you are modifying the same thing in memory.

Why does the fans object in the function become a reference for the fans object in Context? Does it happen with flow.set or return fans? Do I need to copy it to Context differently? I expected the two objects to be completely separate. BTW I'm enjoying Node Red, but I'm just learning as I go here. Sometimes just enough to be dangerous :crazy_face:

It doesn't become a reference... it never stops being a reference. You put the 'fans' object into context and then you pass the same object on.

You can clone it before returning to break the link:

return RED.util.cloneMessage(fans);