From 2387761f73bd3909572093697bf5b0d6432f9233 Mon Sep 17 00:00:00 2001 From: Martin Mares <mj@ucw.cz> Date: Tue, 14 Apr 2020 12:59:03 +0200 Subject: [PATCH] Hook: Reset DB transaction at the end of each request --- hook/hook.wsgi | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hook/hook.wsgi b/hook/hook.wsgi index d0828e6..36ea076 100644 --- a/hook/hook.wsgi +++ b/hook/hook.wsgi @@ -38,6 +38,15 @@ def db_query(query, args=()): db_connect() db.execute(query, args) +def db_reset(): + # At the end of every request, we have to close the implicitly opened + # transaction. Otherwise we end up with serving stale data. + if db_connection is not None: + try: + db_connection.rollback() + except: + pass + ### Utilities ### def parse_time(iso_time): @@ -279,3 +288,5 @@ def application(env, start_response): except Exception as exc: app.log(traceback.print_exception(etype=None, value=exc, tb=exc.__traceback__)) return app.http_error(500, "Internal server error") + finally: + db_reset() -- GitLab