GitHub user dosubot[bot] added a comment to the discussion: Warm up charts cache via API
<!-- Answer --> This error occurs because [modern (non-legacy) charts require a `query_context` field to be stored in the database](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/commands/chart/warm_up_cache.py#L77-L87), and your chart doesn't have one saved. The `query_context` is typically populated automatically when you **save a chart through the Superset UI**. If your chart was created programmatically or the query_context was never stored, it will be missing. **Solutions:** 1. **Re-save the chart via the UI** — Open the chart in Explore, make a trivial change (or just click Save), and it will store the query_context. Then warm_up_cache will work. 2. **Use your original approach** — Your initial workflow actually makes sense for charts without stored query_context: ``` GET /api/v1/chart/{chart_id} → get form_data from response POST /api/v1/chart/data → build query_context from form_data and execute ``` This bypasses the need for stored query_context since you're constructing it dynamically. 3. **Update the chart via API** — If you want warm_up_cache to work long-term, you can update the chart with query_context: ``` PUT /api/v1/chart/{chart_id} {"query_context": "<json_string>"} ``` For approach #2, you'd need to construct the query_context JSON from the chart's form_data. The [query_context structure](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/models/slice.py#L289-L298) is what Superset uses internally to execute queries. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/b920004e-5366-40e4-9d4a-218d474681b7?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b920004e-5366-40e4-9d4a-218d474681b7?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b920004e-5366-40e4-9d4a-218d474681b7?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b920004e-5366-40e4-9d4a-218d474681b7?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b920004e-5366-40 e4-9d4a-218d474681b7?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b920004e-5366-40e4-9d4a-218d474681b7?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report) | [Other](https://app.dosu.dev/response-feedback/b920004e-5366-40e4-9d4a-218d474681b7?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge) [](https://cursor.com/link/prompt?text=This%20error%20occurs%20because%20%5Bmodern%20%28non-legacy%29%20charts%20require%20a%20%60query_context%60%20field%20to%20be%20stored%20in%20the%20database%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/commands/chart/warm_up_cache.py%23L77-L87%29%2C%20and%20your%20chart%20doesn%27t%20have%20one%20saved.%0A%0AThe%20%60query_context%60%20is%20typically%20populated%20automatically%20when%20you%20%2A%2Asave%20a%20chart%20through%20the%20Superset%20UI%2A%2A.%20If%20your%20chart%20was%20created%20programmatically%20or%20the%20query_context%20was%20never%20stored%2C%20it%20will%20be%20missing.%0A%0A%2A%2ASolutions%3A%2A%2A%0A%0A1.%2 0%2A%2ARe-save%20the%20chart%20via%20the%20UI%2A%2A%20%E2%80%94%20Open%20the%20chart%20in%20Explore%2C%20make%20a%20trivial%20change%20%28or%20just%20click%20Save%29%2C%20and%20it%20will%20store%20the%20query_context.%20Then%20warm_up_cache%20will%20work.%0A%0A2.%20%2A%2AUse%20your%20original%20approach%2A%2A%20%E2%80%94%20Your%20initial%20workflow%20actually%20makes%20sense%20for%20charts%20without%20stored%20query_context%3A%0A%20%20%20%60%60%60%0A%20%20%20GET%20/api/v1/chart/%7Bchart_id%7D%20%E2%86%92%20get%20form_data%20from%20response%0A%20%20%20POST%20/api/v1/chart/data%20%E2%86%92%20build%20query_context%20from%20form_data%20and%20execute%0A%20%20%20%60%60%60%0A%20%20%20This%20bypasses%20the%20need%20for%20stored%20query_context%20since%20you%27re%20constructing%20it%20dynamically.%0A%0A3.%20%2A%2AUpdate%20the%20chart%20via%20API%2A%2A%20%E2%80%94%20If%20you%20want%20warm_up_cache%20to%20work%20long-term%2C%20you%20can%20update%20the%20chart%20with%20query_context%3A%0A%20%20 %20%60%60%60%0A%20%20%20PUT%20/api/v1/chart/%7Bchart_id%7D%0A%20%20%20%7B%22query_context%22%3A%20%22%3Cjson_string%3E%22%7D%0A%20%20%20%60%60%60%0A%0AFor%20approach%20%232%2C%20you%27d%20need%20to%20construct%20the%20query_context%20JSON%20from%20the%20chart%27s%20form_data.%20The%20%5Bquery_context%20structure%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/models/slice.py%23L289-L298%29%20is%20what%20Superset%20uses%20internally%20to%20execute%20queries.) [](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/38718) GitHub link: https://github.com/apache/superset/discussions/38718#discussioncomment-16191397 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
