Page MenuHome

Python custom Operators fail to Undo properly if executed while in edit mode
Open, Confirmed, MediumPublic


System Information
Operating system: Win10
Graphics card: nVidia Quadro 600

Blender Version
Broken: 2.80 26c8e09cffd
Worked: Unknown

Short description of error
Python custom Operators fail to Undo properly if executed while in edit mode

I've provided 3 operators that all show incorrect behavior if executed while you are working in edit mode. They may all be the same systemic issue or different, for now you can take your pick on which, or all, you repro with.

The behavior can change depending on if you use the REGISTER,UNDO tags and if you use a manual bpy.ops.ed.undo_push() (_none of which are attempted below_) but several tries at addressing the issue have been unsuccessful:

Exact steps for others to reproduce the error

  • Start blender with --factory-startup option
  • Load the attached .blend:
    • Reload this .blend for each individual repro
    • You should be placed in editmode -- this is important. Do not manually switch modes during the repro
  • Invoke 1 of the 3 operators provided by using the built in script editor / py console etc:
    • bpy.ops.view3d.rb_collection_undo_issue() - Adds a new collection to the scene, moves the object named "Cube" to that new collection
    • bpy.ops.view3d.rb_mod_undo_issue() - Adds a modifier to the object named "Cube"
    • bpy.ops.view3d.rb_separate_undo_issue() - Takes currently selected geo and separates into new object
  • Invoke CTRL-Z Undo
    • Notice how none of the actions are undone properly
  • Invoke CTRL-Z Undo a second time; this time the actions are undone because the undo stack passes through the edit-mode toggle as set in the file
    • If you were to perform N other actions between edit-mode toggle and the operator in question, you basically have to CTRL-Z undo N+1 times before the state is undone



Event Timeline

Sebastian Parborg (zeddb) triaged this task as Confirmed, Medium priority.Dec 14 2018, 12:23 PM

I can confirm that I need to invoke undo two times for this to undo properly (or well, not properly in this case).

@Brecht Van Lommel (brecht) who to assign this to?

@Campbell Barton (campbellbarton) worked on the undo system last, and probably knows if this is a bug or a limitation.