{"record":{"id":"fa4b8d505b9d3dd7","repo":"apache/superset","slug":"chart-s-query-context-does-not-exist-open-the-cha","errorCode":null,"errorMessage":"Chart's query context does not exist. Open the chart in Explore once (or re-save it) to generate it.","messagePattern":"Chart's query context does not exist\\. Open the chart in Explore once \\(or re-save it\\) to generate it\\.","errorType":"validation","errorClass":"ChartInvalidError","httpStatus":422,"severity":"error","filePath":"superset/commands/chart/warm_up_cache.py","lineNumber":63,"sourceCode":"        self._dashboard_id = dashboard_id\n        self._extra_filters = extra_filters\n\n    def _get_dashboard_filters(self, chart_id: int) -> list[dict[str, Any]]:\n        \"\"\"Retrieve dashboard filters from extra_filters or dashboard metadata.\"\"\"\n        if not self._dashboard_id:\n            return []\n\n        if self._extra_filters:\n            return json.loads(self._extra_filters)\n\n        return get_dashboard_extra_filters(chart_id, self._dashboard_id)\n\n    def _warm_up_non_legacy_cache(self, chart: Slice) -> tuple[Any, Any]:\n        \"\"\"Warm up cache for non-legacy visualizations.\"\"\"\n        query_context = chart.get_query_context()\n\n        if not query_context:\n            raise ChartInvalidError(\n                \"Chart's query context does not exist. Open the chart in \"\n                \"Explore once (or re-save it) to generate it.\"\n            )\n\n        # Apply dashboard filters if dashboard_id is provided\n        if dashboard_filters := self._get_dashboard_filters(chart.id):\n            for query in query_context.queries:\n                query.filter = (\n                    cast(list[QueryObjectFilterClause], dashboard_filters)\n                    + query.filter\n                )\n\n        query_context.force = True\n        command = ChartDataCommand(query_context)\n        command.validate()\n        payload = command.run()\n\n        # Report the first error.","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/chart/warm_up_cache.py#L45-L81","documentation":"Raised as ChartInvalidError by WarmUpCacheCommand._warm_up_non_legacy_cache when chart.get_query_context() returns None: the chart has no persisted query context payload. Non-legacy charts need a stored query context (generated when the chart is opened in Explore or saved) for cache warm-up; a chart that skipped that step cannot be warmed.","triggerScenarios":"POST /api/v1/chart/warm_up_cache with a chart id whose params were created/migrated without ever generating query_context; charts created programmatically (API/factory) that were never opened in Explore; legacy charts not yet touched since the query-context migration.","commonSituations":"Bulk-warming caches right after a Superset upgrade or after seeding charts via scripts; warming charts created by older export/import flows.","solutions":["Open the chart in Explore and save it once — this generates and persists the query context — then retry warm-up.","Programmatically PUT the chart with a valid query_context payload before warming.","Skip legacy charts or handle this error per-chart in bulk warm-up loops."],"exampleFix":"# before\nclient.post('/api/v1/chart/warm_up_cache', json={'chart_id': 42})\n# ChartInvalidError: Chart's query context does not exist...\n\n# after: force query-context generation, then warm\nclient.put('/api/v1/chart/42', json={'query_context': refreshed_context})\nclient.post('/api/v1/chart/warm_up_cache', json={'chart_id': 42})","handlingStrategy":"validation","validationCode":"chart = ChartDAO.find_by_id(chart_id)\nif chart.get_query_context() is None:\n    raise ValueError('chart lacks query_context; open in Explore and save first')","typeGuard":"def has_query_context(chart) -> bool:\n    return chart.get_query_context() is not None","tryCatchPattern":"from superset.commands.chart.exceptions import ChartInvalidError\ntry:\n    WarmUpCacheCommand(chart_id=chart_id).run()\nexcept ChartInvalidError as ex:\n    if 'query context does not exist' in str(ex):\n        open_in_explore_and_save(chart_id)  # then retry","preventionTips":["Open every chart in Explore once after upgrades or programmatic creation.","Skip or pre-save charts without query_context in bulk warm-up jobs."],"tags":["chart","cache","warm-up","query-context"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}