mirror of
https://github.com/apache/superset.git
synced 2026-04-20 08:34:37 +00:00
fix: logs table - user_id is NULL (#14057)
* add user back to session * add test for logging None on exceptions * fix this updated test * reformat * reformat * Update log.py
This commit is contained in:
@@ -118,12 +118,23 @@ class AbstractEventLogger(ABC):
|
||||
|
||||
duration_ms = int(duration.total_seconds() * 1000) if duration else None
|
||||
|
||||
# Initial try and grab user_id via flask.g.user
|
||||
try:
|
||||
user_id = g.user.get_id()
|
||||
except Exception as ex: # pylint: disable=broad-except
|
||||
logging.warning(ex)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
user_id = None
|
||||
|
||||
# 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:
|
||||
try:
|
||||
session = current_app.appbuilder.get_session
|
||||
session.add(g.user)
|
||||
user_id = g.user.get_id()
|
||||
except Exception as ex: # pylint: disable=broad-except
|
||||
logging.warning(ex)
|
||||
user_id = None
|
||||
|
||||
payload = collect_request_payload()
|
||||
if object_ref:
|
||||
payload["object_ref"] = object_ref
|
||||
|
||||
Reference in New Issue
Block a user