Compare commits

...

1 Commits

Author SHA1 Message Date
Vitor Avila
fdb4261a98 fix: Prevent 'Working outside of application context' errors on Celery 2026-03-05 14:28:04 -03:00

View File

@@ -63,9 +63,10 @@ def teardown( # pylint: disable=unused-argument
:see: https://gist.github.com/twolfson/a1b329e9353f9b575131
"""
if flask_app.config.get("SQLALCHEMY_COMMIT_ON_TEARDOWN"):
if not isinstance(retval, Exception):
db.session.commit() # pylint: disable=consider-using-transaction
with flask_app.app_context():
if flask_app.config.get("SQLALCHEMY_COMMIT_ON_TEARDOWN"):
if not isinstance(retval, Exception):
db.session.commit() # pylint: disable=consider-using-transaction
if not flask_app.config.get("CELERY_ALWAYS_EAGER"):
db.session.remove()
if not flask_app.config.get("CELERY_ALWAYS_EAGER"):
db.session.remove()