Help with nodes, node operator and script

OK, can somebody explain this to me?

I can do this in a script and it works

Add nodes
Run node operator

If I try this I get a error. Also, get the same error without the grease pencil ,but yet one got added. It’s like it doesn’t detect that the grease pencil stroke got added

Add nodes
Add grease pencil stroke
Run node operator

I can break it up and it also works

Add nodes
Add grease pencil stroke

then run this after

Run node operator

How can I run all three lines together?

Especially the last line sounds like you could be affected by this: https://docs.blender.org/api/current/info_gotcha.html#stale-data

You talking about do bpy.context.view_layer.update()? I tried that after the grease pencil before the last line and it made no difference. I can post code if somebody wants to test ,but requires enabling this add-on.

Need to make sure it’s the 2.8 version.