This is an automated email from the ASF dual-hosted git repository. vavila pushed a commit to branch fix/celery-outside-of-context-error in repository https://gitbox.apache.org/repos/asf/superset.git
commit fdb4261a98608ac58288ee24498b021689382315 Author: Vitor Avila <[email protected]> AuthorDate: Thu Mar 5 14:28:04 2026 -0300 fix: Prevent 'Working outside of application context' errors on Celery --- superset/tasks/celery_app.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/superset/tasks/celery_app.py b/superset/tasks/celery_app.py index 2049246f042..8bbde5b2677 100644 --- a/superset/tasks/celery_app.py +++ b/superset/tasks/celery_app.py @@ -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()
