Workaround for deleting a lattice object in an operator related crash?

Hi

I filed this bug https://developer.blender.org/T65681, which is about an undo done by the user after a lattice object is deleted by an operator causes a crash.

I am wondering if there is a work around for the given bug until it is fixed? I was about to release my addon but now I feel like I cant because well I do not want users crashing Blender and loosing their work.

There is a simple sample add-on that causes the crash and how to steps in the bug report.

thanks

There is a recommendation by Joseph Eagar (joeedh) which overcomes the crashes I explained in my top post.

If you are facing a similar issue here is the recommended solution which works with my initial testing, I am hoping that I wont face any more surprises with this issue.

Okay, looks like the problem is with the undo system; if you manually exit editmode then push the understack, e.g.:

bpy.ops.object.editmode_toggle()
bpy.ops.ed.undo_push()