From bac4e01f40ae7bd19d1eab1fb9349452c18de8f5 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 21 Apr 2019 12:02:24 -0700 Subject: [PATCH] Ensure sqlite_timelimit correctly clears handler If an error occurred inside the block the progress handler (used to enforce a time limit) was not being correctly cleared, resulting in timeout errors potentially occurring during subsequent SQL queries. The fix is described here: https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager --- datasette/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/datasette/utils.py b/datasette/utils.py index 0c161ac6..7ebf4f23 100644 --- a/datasette/utils.py +++ b/datasette/utils.py @@ -152,8 +152,10 @@ def sqlite_timelimit(conn, ms): return 1 conn.set_progress_handler(handler, n) - yield - conn.set_progress_handler(None, n) + try: + yield + finally: + conn.set_progress_handler(None, n) class InvalidSql(Exception):