piccolo
piccolo copied to clipboard
Give a warning when a database query goes out of scope before being run?
A common bug I've run into is forgetting to add a .save.run_sync() to the end of my queries, which leads to no action being taken. Unlike queries which will give typing errors if you forget (we love you Mypy). It could be a good idea to give a warning if a database query goes out of scope before being run, since that would point out the error. If there are any better alternative ways to help people avoid this bug, those could also be considered.
You can run Python in development mode, which logs a warning when a coroutine isn't awaited:
https://docs.python.org/3/library/asyncio-dev.html#asyncio-debug-mode
We could mention this in the docs.
We might be able to add something to the Piccolo framework to detect coroutines that haven't been awaited. It would be tricky though. Some kind of context manager perhaps.
Cool - I suppose it's less of an issue for when you run it async - sadly I haven't been able to do that for my project due to time constraints. Yeah it is probably a pretty complex request, and not exactly the most high priority thing ever.