getredash/redash · error · Exception
Python query helpers require a current user.
Error message
Python query helpers require a current user.
What it means
Python query helpers (_get_data_source, get_query_result, get_current_user) execute with the identity of the user who triggered execution, stored as runner._current_user. If it is unset, any helper call raises this Exception — the runner can't safely authorize access without knowing the user.
Source
Thrown at redash/query_runner/python.py:306
):
raise Exception("You do not have access to query id %s." % query_id)
return query.latest_query_data.data
def dataframe_to_result(self, result, df):
converted_result = pandas_to_result(df)
result["rows"] = converted_result["rows"]
for column in converted_result["columns"]:
self.add_result_column(result, column["name"], column["friendly_name"], column["type"])
def get_current_user(self):
return self._get_current_user().to_dict()
def _get_current_user(self):
user = getattr(self, "_current_user", None)
if user is None:
raise Exception("Python query helpers require a current user.")
return user
def test_connection(self):
pass
def validate_result(self, result):
"""Validate the result after executing the query.
Parameters:
:result dict: The result dict.
"""
if not result:
raise Exception("local variable `result` should not be empty.")
if not isinstance(result, dict):
raise Exception("local variable `result` should be of type `dict`.")
if "rows" not in result:
raise Exception("Missing `rows` field in `result` dict.")
if "columns" not in result:View on GitHub (pinned to ca79fe988d)
Solutions
- Restart/upgrade all query worker processes so they run the version that injects the current user
- Trigger execution as a logged-in user (normal 'Execute' in the UI) rather than via contexts without a user
- In embedded tooling, ensure the execution request carries the user and the runner sets _current_user before helpers are called
- Check for None before calling helpers and fail with a clearer message
Example fix
# before
result = get_query_result(123) # may raise if no current user
# after
user = getattr(runner, '_current_user', None)
if user is None:
result = {'rows': [], 'columns': []} # skip or handle
else:
result = get_query_result(123) Defensive patterns
Strategy: type-guard
Validate before calling
if getattr(runner, '_current_user', None) is None:
raise Skip('No current user; cannot use query helpers') Type guard
def helpers_available(runner) -> bool:
return getattr(runner, '_current_user', None) is not None Try / catch
try:
result = get_query_result(qid)
except Exception as e:
if 'require a current user' in str(e):
result = {'rows': [], 'columns': []} # graceful empty result Prevention
- Run Python queries through a real user session; avoid headless/legacy paths
- Restart workers after upgrades so user-context injection is active
When it happens
Trigger: Executing a Python query that calls execute_query()/get_query_result()/get_source_schema()/get_current_user() via a path that doesn't set _current_user — e.g. test_connection, API key executions, older workers/celery tasks that never injected the user, or ad-hoc runs before the feature existed.
Common situations: Upgrading Redash where the query was previously runnable but user context injection wasn't wired (workers not restarted after upgrade); running through a scheduler context that lacks a user; direct worker testing.
Related errors
- You do not have access to data source: %s.
- You do not have access to query id %s.
- '{0}' is not configured as a supported import module
- '{} is not supported inplace variable
- '{0}' is not a supported column type
AI-assisted analysis of getredash/redash@ca79fe988d (2026-08-28).
Data as JSON: /api/errors/f694d74972219b51.
Report an issue: GitHub.