Reputation: 3348
I know simmilar questions have been answered here, but the thing is:
I have some unit tests and they sometimes run okay, but sometimes I get a "Parent instance is not bound to a Session"
So how would I start debugging something like that if it only happens randomly.
Oh, and the call before the error was db.session.add(my_item)
.
Upvotes: 4
Views: 450
Reputation: 83676
How often this happens? As the starting point would be probably put a breakpoint of your favorite Python debugger (pdb) on the line where the exception is thrown. Then, when you encounter the error you will inspect the application state in the Python debugger, step up in stack frames and figure out how your application ended up in such state.
Also extensive use of Python loggers and writing out DEBUG
log level messages often help to pinpoint the actual cause of the error.
Upvotes: 1