chore: proper current_app.config proxy usage (#34345)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Maxime Beauchemin
2025-07-31 19:27:42 -07:00
committed by GitHub
parent 6c9cda758a
commit cb27d5fe8d
144 changed files with 1428 additions and 1119 deletions

View File

@@ -721,19 +721,24 @@ def test_apply_dynamic_database_filter(
# Ensure that the filter has not been called because it's not in our config
assert base_filter_mock.call_count == 0
original_config = current_app.config.copy()
original_config["EXTRA_DYNAMIC_QUERY_FILTERS"] = {"databases": base_filter_mock}
# Temporarily update the config
original_filters = current_app.config.get("EXTRA_DYNAMIC_QUERY_FILTERS", {})
current_app.config["EXTRA_DYNAMIC_QUERY_FILTERS"] = {
"databases": base_filter_mock
}
try:
# Get filtered list
response_databases = DatabaseDAO.find_all()
assert response_databases
expected_db_names = ["second-database"]
actual_db_names = [db.database_name for db in response_databases]
assert actual_db_names == expected_db_names
mocker.patch("superset.views.filters.current_app.config", new=original_config)
# Get filtered list
response_databases = DatabaseDAO.find_all()
assert response_databases
expected_db_names = ["second-database"]
actual_db_names = [db.database_name for db in response_databases]
assert actual_db_names == expected_db_names
# Ensure that the filter has been called once
assert base_filter_mock.call_count == 1
# Ensure that the filter has been called once
assert base_filter_mock.call_count == 1
finally:
# Restore original config
current_app.config["EXTRA_DYNAMIC_QUERY_FILTERS"] = original_filters
def test_oauth2_happy_path(

View File

@@ -19,6 +19,7 @@
import copy
import pytest
from flask import current_app
from pytest_mock import MockerFixture
from sqlalchemy.orm.session import Session
@@ -97,12 +98,12 @@ def test_import_database_sqlite_invalid(
"""
Test importing a database.
"""
from superset import app, security_manager
from superset import security_manager
from superset.commands.database.importers.v1.utils import import_database
from superset.models.core import Database
from tests.integration_tests.fixtures.importexport import database_config_sqlite
app.config["PREVENT_UNSAFE_DB_CONNECTIONS"] = True
current_app.config["PREVENT_UNSAFE_DB_CONNECTIONS"] = True
mocker.patch.object(security_manager, "can_access", return_value=True)
engine = db.session.get_bind()
@@ -116,7 +117,7 @@ def test_import_database_sqlite_invalid(
== "SQLiteDialect_pysqlite cannot be used as a data source for security reasons." # noqa: E501
)
# restore app config
app.config["PREVENT_UNSAFE_DB_CONNECTIONS"] = True
current_app.config["PREVENT_UNSAFE_DB_CONNECTIONS"] = True
def test_import_database_managed_externally(

View File

@@ -60,8 +60,7 @@ def test_database_filter_full_db_access(mocker: MockerFixture) -> None:
"""
from superset.models.core import Database
current_app = mocker.patch("superset.databases.filters.current_app")
current_app.config = {"EXTRA_DYNAMIC_QUERY_FILTERS": False}
mocker.patch("flask.current_app.config", {"EXTRA_DYNAMIC_QUERY_FILTERS": False})
mocker.patch.object(security_manager, "can_access_all_databases", return_value=True)
engine = create_engine("sqlite://")
@@ -81,8 +80,7 @@ def test_database_filter(mocker: MockerFixture) -> None:
"""
from superset.models.core import Database
current_app = mocker.patch("superset.databases.filters.current_app")
current_app.config = {"EXTRA_DYNAMIC_QUERY_FILTERS": False}
mocker.patch("flask.current_app.config", {"EXTRA_DYNAMIC_QUERY_FILTERS": False})
mocker.patch.object(
security_manager,
"can_access_all_databases",