This is not a good usage pattern, as this will usually lead to ''Cannot operate on a closed cursor'' kind of error, especially for PySqlite. It happens to work in this case because the db is kept alive higher in the call stack.
Spotted by Grzegorz Sobanski, thanks!