Skip to content

fix: LocalProxy is not mapped warning #33025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions superset/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from datetime import datetime, timedelta
from typing import Any, Callable, cast, Literal, TYPE_CHECKING

from flask import g, request
from flask import g, has_request_context, request
from flask_appbuilder.const import API_URI_RIS_KEY
from sqlalchemy.exc import SQLAlchemyError

Expand Down Expand Up @@ -193,14 +193,15 @@ def log_with_context( # pylint: disable=too-many-locals,too-many-arguments

# Whenever a user is not bounded to a session we
# need to add them back before logging to capture user_id
if user_id is None:
if user_id is None and has_request_context():
try:
db.session.add(g.user)
user_id = get_user_id()
except Exception as ex: # pylint: disable=broad-except
logging.warning(ex)
actual_user = g.get("user", None)
if actual_user is not None:
db.session.add(actual_user)
user_id = get_user_id()
except Exception as ex:
logging.warning("Failed to add user to db session: %s", ex)
user_id = None

payload = collect_request_payload()
if object_ref:
payload["object_ref"] = object_ref
Expand Down
Loading