apache/superset · error · ChartDataQueryFailedError

Error: %(error)s

Error message

Error: %(error)s

What it means

ChartDataQueryFailedError raised in ChartDataCommand.run() (get_data_command.py:60) when any query payload carries an 'error' entry after execution. get_payload() collects per-query exceptions (SQL errors, engine failures, timeout) into payload['queries'][i]['error'] instead of raising; this loop converts them to a command exception with the message interpolated into 'Error: %(error)s'. Skipped when result_type is QUERY (View Query modal wants the error in-band).

Source

Thrown at superset/commands/chart/data/get_data_command.py:60

        # caching is handled in query_context.get_df_payload
        # (also evals `force` property)
        cache_query_context = kwargs.get("cache", False)
        force_cached = kwargs.get("force_cached", False)
        try:
            payload = self._query_context.get_payload(
                cache_query_context=cache_query_context, force_cached=force_cached
            )
        except CacheLoadError as ex:
            raise ChartDataCacheLoadError(ex.message) from ex

        # Skip error check for query-only requests - errors are returned in payload
        # This allows View Query modal to display validation errors
        for query in payload["queries"]:
            if (
                query.get("error")
                and self._query_context.result_type != ChartDataResultType.QUERY
            ):
                raise ChartDataQueryFailedError(
                    _("Error: %(error)s", error=query["error"])
                )

        return_value = {
            "query_context": self._query_context,
            "queries": payload["queries"],
        }
        if cache_query_context:
            return_value.update(cache_key=payload["cache_key"])

        return return_value

    def execute(self, **kwargs: Any) -> ChartDataExecutionResult:
        """Execute and return timing as a typed sidecar."""
        cache_query_context = kwargs.get("cache", False)
        force_cached = kwargs.get("force_cached", False)
        try:
            result = self._query_context.get_payload_result(

View on GitHub (pinned to f4587218dd)

Solutions

  1. Read the interpolated database error text — it names the real cause (column, table, timeout).
  2. Open the chart in Explore and run 'View Query' (result_type=query) to get the in-band error plus generated SQL for debugging.
  3. Fix the dataset/chart definition (re-add missing column, adjust time grain/metric) or the underlying table, then re-run.
  4. For timeouts, raise SQLLAB_QUERY_TIME_LIMIT or optimize the query.

Example fix

# before
result = ChartDataCommand(qc).run()  # raises ChartDataQueryFailedError('Error: column X not found')

# after
qc.result_type = ChartDataResultType.QUERY
result = ChartDataCommand(qc).run()  # error returned in-band; inspect result['queries'][0]['error'] and ['query']
Defensive patterns

Strategy: try-catch

Validate before calling

# cheap pre-flight: confirm the dataset/table still resolves
from superset.utils.core import get_datasource_by_id

ds = get_datasource_by_id(query_context.datasource.id, query_context.datasource.type)
if ds is None:
    return {"error": "datasource missing; refresh chart dataset"}, 400

Try / catch

try:
    result = ChartDataCommand(qc).run()
except ChartDataQueryFailedError as ex:
    db_error = str(ex).removeprefix("Error: ")
    log.warning("query failed: %s", db_error)
    return {"error": db_error}, 500

Prevention

When it happens

Trigger: POST /api/v1/chart/data where the underlying database rejects the SQL (syntax error, unknown column, missing table), the query times out, or the engine driver raises; any result type other than 'query' (e.g. results, samples) triggers the raise.

Common situations: Chart referencing a column dropped from the dataset; DB connection expired/invalid; query timeouts on large tables; wrong SQL clause in custom SQL metrics.

Related errors


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