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_type

View on GitHub (pinned to f4587218dd)

Solutions

  1. Open the chart in Explore and re-save it — this persists a fresh, valid query_context
  2. Then re-run the report schedule
  3. 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

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


AI-assisted analysis of apache/superset@f4587218dd (2026-08-14). Data as JSON: /api/errors/b8f2b348180b1a2b. Report an issue: GitHub.