apache/superset · error · ReportScheduleExecuteUnexpectedError
Chart has no valid query context saved.
Error message
Chart has no valid query context saved.
What it means
ReportScheduleExecuteUnexpectedError('Chart has no valid query context saved.') from the CSV/XLSX export payload builder: it json.loads(self._report_schedule.chart.query_context); TypeError (query_context is None — chart saved before query_context existed, or column empty) or json.JSONDecodeError (corrupt/truncated JSON) is wrapped with this message chained to the cause.
Source
Thrown at superset/commands/report/execute.py:890
return pdf
def _get_chart_data_request_payload(
self,
result_format: ChartDataResultFormat,
) -> dict[str, Any]:
"""
Build the POST payload used for chart data exports.
:param result_format: Desired table-like chart data format.
:return: Query context updated with export result format/type and pagination.
:raises ReportScheduleExecuteUnexpectedError: If the chart query context is
missing or invalid.
"""
try:
query_context = json.loads(self._report_schedule.chart.query_context)
except (TypeError, json.JSONDecodeError) as ex:
raise ReportScheduleExecuteUnexpectedError(
"Chart has no valid query context saved."
) from ex
if not isinstance(query_context, dict):
raise ReportScheduleExecuteUnexpectedError(
"Chart has no valid query context saved."
)
result_type = ChartDataResultType.POST_PROCESSED.value
force = bool(self._report_schedule.force_screenshot)
query_context["result_format"] = result_format.value
query_context["result_type"] = result_type
query_context["force"] = force
form_data = query_context.get("form_data")
if isinstance(form_data, dict):
form_data["result_format"] = result_format.value
form_data["result_type"] = result_typeView on GitHub (pinned to f4587218dd)
Solutions
- Open the chart in Explore and re-save it — this persists a fresh, valid query_context
- Then re-run the report schedule
- For bulk legacy charts, resave via the API (PUT /api/v1/chart/{id} after a GET) or a migration backfill
Example fix
# before
chart.query_context = None # legacy chart; CSV report execution fails
# after
# open chart in Explore, click Save (or):
client.put(f'/api/v1/chart/{chart_id}', json={'query_context': refreshed_query_context}) Defensive patterns
Strategy: validation
Validate before calling
import json
def chart_exportable(chart) -> bool:
if not chart.query_context:
return False
try:
return isinstance(json.loads(chart.query_context), dict)
except (TypeError, json.JSONDecodeError):
return False Type guard
def has_valid_query_context(chart) -> bool:
"""True when query_context is a JSON object usable for export."""
try:
return isinstance(json.loads(chart.query_context), dict)
except (TypeError, json.JSONDecodeError):
return False Try / catch
try:
_get_data(result_format)
except ReportScheduleExecuteUnexpectedError as ex:
if 'query context' in str(ex):
# resave chart in Explore, then re-run
schedule_chart_resave(chart_id) Prevention
- Resave legacy charts in Explore before pointing CSV/XLSX reports at them
- Backfill query_context during migrations rather than leaving NULLs
- Add the has_valid_query_context check to report creation validation for data exports
When it happens
Trigger: A report with delivery format CSV/XLSX whose chart has query_context NULL (legacy charts never opened in Explore since query_context persistence was added) or a manually corrupted query_context string; execution reaches _get_csv_data's payload builder.
Common situations: Old charts created before query_context was always persisted; charts whose query_context got truncated by a migration; reports configured for data export against such charts.
Related errors
- Unsupported chart data result format: {result_format}
- The chart this report targets was deleted. Restore the chart
- Report schedule {id} ({name!r}) has no resolvable target (ch
- validation_error
- security_error
AI-assisted analysis of apache/superset@f4587218dd (2026-08-14).
Data as JSON: /api/errors/b8f2b348180b1a2b.
Report an issue: GitHub.