Maya undo queue is showing None but still able to undo

I am trying to print out the undo queue using the following command:

cmds.undoInfo(query=True, printQueue=True)

as a means to check the custom undo chunk I have created. And I will get the following:

# 0:  # 
# 1: my_customChunk # 
...
# 10: my_customChunk # 

For my sanity sake, before I launch my tool, I perform cmds.flushUndo() to keep the undo queue ‘clean’ and easier for me to see what is going on with my tool.

However, at times, when I tried to use the first command to print out the queue, instead of seeing the numbered queue, I am not getting None even though I am still able to perform undo.

Is this perhaps a sign of my doing the flushUndo a bad thing, and/ or something is going on with the custom chunks I have created?

If not, does anyone have any tips/ tricks where I can hopefully print out the proper numbered queue again? My current solution is to restart Maya session whenever I hit this problem which is not ideal.

I think I may have figured this out. So it seems that one of the custom undoChunk is not closing properly and hence the queue appears to be empty when queried when it is not.

When doing custom undo chunks, you pretty much always want to use a try / finally pair to ensure that close is always called. Better yet is writing a custom context manager so you can use with new_undo('chunk'): and be certain that it is always closed out for you.