From 12921e6ec37bf571bb828f824f7a9b5e3cdca8ba Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Tue, 26 Mar 2024 12:18:36 -0700 Subject: [PATCH] =?UTF-8?q?chore(=F0=9F=A4=96):=20bump=20python=20"flask?= =?UTF-8?q?=3D=3D2.3.3"=20(#27657)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements/base.txt | 4 +++- tests/integration_tests/celery_tests.py | 28 ++++++++++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/requirements/base.txt b/requirements/base.txt index 950e0789c3..27adb58a4e 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -30,6 +30,8 @@ bcrypt==4.0.1 # via paramiko billiard==4.2.0 # via celery +blinker==1.7.0 + # via flask bottleneck==1.3.7 # via pandas brotli==1.0.9 @@ -92,7 +94,7 @@ email-validator==1.1.3 # via flask-appbuilder exceptiongroup==1.2.0 # via cattrs -flask==2.2.5 +flask==2.3.3 # via # apache-superset # flask-appbuilder diff --git a/tests/integration_tests/celery_tests.py b/tests/integration_tests/celery_tests.py index 53e7b217ee..5774d8920a 100644 --- a/tests/integration_tests/celery_tests.py +++ b/tests/integration_tests/celery_tests.py @@ -30,7 +30,7 @@ from tests.integration_tests.fixtures.birth_names_dashboard import ( import pytest import flask -from flask import current_app +from flask import current_app, has_app_context from superset import db, sql_lab from superset.common.db_query_status import QueryStatus @@ -473,19 +473,23 @@ def test_create_table_as(): def test_in_app_context(): - @celery_app.task() - def my_task(): - assert current_app + @celery_app.task(bind=True) + def my_task(self): + # Directly check if an app context is present + return has_app_context() - # Make sure we can call tasks with an app already setup - my_task() + # Expect True within an app context + with app.app_context(): + result = my_task.apply().get() + assert ( + result is True + ), "Task should have access to current_app within app context" - # Make sure the app gets pushed onto the stack properly - try: - popped_app = flask._app_ctx_stack.pop() - my_task() - finally: - flask._app_ctx_stack.push(popped_app) + # Expect True outside of an app context + result = my_task.apply().get() + assert ( + result is True + ), "Task should have access to current_app outside of app context" def delete_tmp_view_or_table(name: str, db_object_type: str):