mirror of
https://github.com/apache/superset.git
synced 2026-08-12 11:11:01 +00:00
chore: proper current_app.config proxy usage (#34345)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
6c9cda758a
commit
cb27d5fe8d
+18
-8
@@ -67,7 +67,7 @@ import pandas as pd
|
||||
import sqlalchemy as sa
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.x509 import Certificate, load_pem_x509_certificate
|
||||
from flask import current_app, g, request
|
||||
from flask import current_app as app, g, request
|
||||
from flask_appbuilder import SQLA
|
||||
from flask_appbuilder.security.sqla.models import User
|
||||
from flask_babel import gettext as __
|
||||
@@ -1381,7 +1381,9 @@ def create_ssl_cert_file(certificate: str) -> str:
|
||||
:raises CertificateException: If certificate is not valid/unparseable
|
||||
"""
|
||||
filename = f"{md5_sha_from_str(certificate)}.crt"
|
||||
cert_dir = current_app.config["SSL_CERT_PATH"]
|
||||
# pylint: disable=import-outside-toplevel
|
||||
|
||||
cert_dir = app.config["SSL_CERT_PATH"]
|
||||
path = cert_dir if cert_dir else tempfile.gettempdir()
|
||||
path = os.path.join(path, filename)
|
||||
if not os.path.exists(path):
|
||||
@@ -1428,7 +1430,9 @@ class DatasourceName(NamedTuple):
|
||||
|
||||
|
||||
def get_stacktrace() -> str | None:
|
||||
if current_app.config["SHOW_STACKTRACE"]:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
|
||||
if app.config["SHOW_STACKTRACE"]:
|
||||
return traceback.format_exc()
|
||||
return None
|
||||
|
||||
@@ -1867,10 +1871,12 @@ def apply_max_row_limit(
|
||||
>>> apply_max_row_limit(0) # Zero returns default max limit
|
||||
50000
|
||||
"""
|
||||
# pylint: disable=import-outside-toplevel
|
||||
|
||||
max_limit = (
|
||||
current_app.config["TABLE_VIZ_MAX_ROW_SERVER"]
|
||||
app.config["TABLE_VIZ_MAX_ROW_SERVER"]
|
||||
if server_pagination
|
||||
else current_app.config["SQL_MAX_ROW"]
|
||||
else app.config["SQL_MAX_ROW"]
|
||||
)
|
||||
if limit != 0:
|
||||
return min(max_limit, limit)
|
||||
@@ -1894,15 +1900,17 @@ def check_is_safe_zip(zip_file: ZipFile) -> None:
|
||||
:param zip_file:
|
||||
:return:
|
||||
"""
|
||||
# pylint: disable=import-outside-toplevel
|
||||
|
||||
uncompress_size = 0
|
||||
compress_size = 0
|
||||
for zip_file_element in zip_file.infolist():
|
||||
if zip_file_element.file_size > current_app.config["ZIPPED_FILE_MAX_SIZE"]:
|
||||
if zip_file_element.file_size > app.config["ZIPPED_FILE_MAX_SIZE"]:
|
||||
raise SupersetException("Found file with size above allowed threshold")
|
||||
uncompress_size += zip_file_element.file_size
|
||||
compress_size += zip_file_element.compress_size
|
||||
compress_ratio = uncompress_size / compress_size
|
||||
if compress_ratio > current_app.config["ZIP_FILE_MAX_COMPRESS_RATIO"]:
|
||||
if compress_ratio > app.config["ZIP_FILE_MAX_COMPRESS_RATIO"]:
|
||||
raise SupersetException("Zip compress ratio above allowed threshold")
|
||||
|
||||
|
||||
@@ -1939,8 +1947,10 @@ def get_query_source_from_request() -> QuerySource | None:
|
||||
|
||||
|
||||
def get_user_agent(database: Database, source: QuerySource | None) -> str:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
|
||||
source = source or get_query_source_from_request()
|
||||
if user_agent_func := current_app.config["USER_AGENT_FUNC"]:
|
||||
if user_agent_func := app.config["USER_AGENT_FUNC"]:
|
||||
return user_agent_func(database, source)
|
||||
|
||||
return DEFAULT_USER_AGENT
|
||||
|
||||
Reference in New Issue
Block a user