Operator execute is behaving inconsistent between object / edit mode

I have noticed a weird behaviour while working on a operator.
As Im not sure if its a bug or not I thought i just ask here first :smiley:

Now what I have trouble with is that operator execute is behaving inconsistent between object and edit mode.

But the snipped should suffice:

def invoke(self, context, event):      
    obj = bpy.data.objects.new( "empty", None )
    self.obj_name = obj.name

def execute(self, context):    
    obj = context.scene.objects[self.obj_name]

The object lookup in execute will fail in object mode - I guess the undo stack just reverts it so that the empy does not exist anymore. This is fine and understandable, but if you run the same thing in edit mode it does just ‘work’ - the empty is still alive and will be found.

Is this intended to work like this or expected behaviour? Would be nice if anyone can shed some light onto this…
(after a quick test this seems also to be the case in 2.79)

Not sure about the problem itself, it runs fine in object mode and edit mode here and creates an empty in both as long as there is an object selected.

But is there a legitimate reason for having the body of the code in invoke?

This means the operator would fail if its execute method was called instead of invoke, since it would skip invoke entirely.

In my example you have to change the int property in the redo panel otherwise execute is never called.

The idea is to cache stuff on invoke, and just reapply on execute without collecting and processing all the data again.