From b50d32b7c92f131ebcc3b633de6c6e91e28297ec Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Nov 18 2024 15:38:38 +0000 Subject: end_request: only remove db session if it exists (infra 12291) See https://pagure.io/fedora-infrastructure/issue/12291 . Per the traceback there, it's possible to get to `end_request` without ever going through `set_request`, when we hit a problem in authentication. In that case, there is no db session and we crash assuming there is one and trying to remove it. So, let's check it's there first. Signed-off-by: Adam Williamson --- diff --git a/pagure/flask_app.py b/pagure/flask_app.py index e9baa50..68578cb 100644 --- a/pagure/flask_app.py +++ b/pagure/flask_app.py @@ -540,7 +540,8 @@ def end_request(exception=None): Details: https://pagure.io/pagure/issue/2302 """ - flask.g.session.remove() + if hasattr(flask.g, "session") and flask.g.session: + flask.g.session.remove() gc.collect()