is this inside a button action perhaps?
You cannot put a blocking function inside a button action, or other methods that are called on the ui thread. The calls to the form need to be called as @ui.in_background if that is the case.
There may be an issue which I have noticed recently when dealing with for examples the photos picker, that presenting a view while another is closing might lead to issues. yOu might try adding a time.sleep() after wait_modal, since this implies you have another view which is getting closed right before this chunk executes.
It might be helpful to see the entire method, or a complete standalone example that shows the issue.