From c40ba05b6736fb42574e204ba5f1ebc4193ecf3c Mon Sep 17 00:00:00 2001 From: Slavek Kabrda Date: Apr 09 2018 11:30:56 +0000 Subject: Make sure we rollback session on task failures This is to make sure that open uncomitted transactions aren't left hanging, which would make subsequent tasks fail --- diff --git a/pagure/lib/tasks.py b/pagure/lib/tasks.py index 1f6d5aa..5d1579d 100644 --- a/pagure/lib/tasks.py +++ b/pagure/lib/tasks.py @@ -70,6 +70,11 @@ def pagure_task(function): session = pagure.lib.create_session(pagure_config['DB_URL']) try: return function(self, session, *args, **kwargs) + except: # noqa: E722 + # if the task has raised for any reason, we need to rollback the + # session first to not leave open uncomitted transaction hanging + session.rollback() + raise finally: session.remove() gc_clean()