diff --git a/files/helpers/cron.py b/files/helpers/cron.py index 864372aef..6ecf39345 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -51,6 +51,7 @@ def cron(every_5m, every_1h, every_1d, every_1mo): g.db.commit() g.db.close() + del g.db stdout.flush() def _sub_inactive_purge_task(): diff --git a/files/routes/allroutes.py b/files/routes/allroutes.py index 9e772b905..fece39fc0 100644 --- a/files/routes/allroutes.py +++ b/files/routes/allroutes.py @@ -43,9 +43,10 @@ def after_request(response): if CLOUDFLARE_AVAILABLE and CLOUDFLARE_COOKIE_VALUE and getattr(g, 'desires_auth', False): logged_in = bool(getattr(g, 'v', None)) response.set_cookie("lo", CLOUDFLARE_COOKIE_VALUE if logged_in else '', max_age=60*60*24*365 if logged_in else 1) - g.db.commit() - g.db.close() - del g.db + if getattr(g, 'db', None): + g.db.commit() + g.db.close() + del g.db return response @app.teardown_appcontext diff --git a/files/routes/errors.py b/files/routes/errors.py index 63104008f..a01e67add 100644 --- a/files/routes/errors.py +++ b/files/routes/errors.py @@ -48,7 +48,10 @@ def error_401(e): @app.errorhandler(500) def error_500(e): - g.db.rollback() + if getattr(g, 'db', None): + g.db.rollback() + g.db.close() + del g.db return error(e) diff --git a/files/routes/oauth.py b/files/routes/oauth.py index 79d17b173..572ac0f2b 100644 --- a/files/routes/oauth.py +++ b/files/routes/oauth.py @@ -32,6 +32,8 @@ def authorize(v): g.db.add(new_auth) except sqlalchemy.exc.IntegrityError: g.db.rollback() + g.db.close() + del g.db old_auth = g.db.query(ClientAuth).filter_by(oauth_client = application.id, user_id = v.id).one() access_token = old_auth.access_token