{"record":{"id":"82893bd1b1e01b1b","repo":"getredash/redash","slug":"no-cached-result-available-for-query","errorCode":null,"errorMessage":"No cached result available for query {}.","messagePattern":"No cached result available for query (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/query_results.py","lineNumber":72,"sourceCode":"        raise PermissionError(\"You do not have access to query id {}.\".format(query.id))\n\n    return query\n\n\ndef replace_query_parameters(query_text, params):\n    qs = parse_qs(params)\n    for key, value in qs.items():\n        query_text = query_text.replace(\"{{{{{my_key}}}}}\".format(my_key=key), value[0])\n    return query_text\n\n\ndef get_query_results(user, query_id, bring_from_cache, params=None):\n    query = _load_query(user, query_id)\n    if bring_from_cache:\n        if query.latest_query_data_id is not None:\n            results = query.latest_query_data.data\n        else:\n            raise Exception(\"No cached result available for query {}.\".format(query.id))\n    else:\n        query_text = query.query_text\n        if params is not None:\n            query_text = replace_query_parameters(query_text, params)\n\n        results, error = query.data_source.query_runner.run_query(query_text, user)\n        if error:\n            raise Exception(\"Failed loading results for query id {}.\".format(query.id))\n\n    return results\n\n\ndef create_tables_from_query_ids(user, connection, query_ids, query_params, cached_query_ids=[]):\n    for query_id in set(cached_query_ids):\n        results = get_query_results(user, query_id, True)\n        table_name = \"cached_query_{query_id}\".format(query_id=query_id)\n        create_table(connection, table_name, results)\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/query_results.py#L54-L90","documentation":"Raised by get_query_results (redash/query_runner/query_results.py:72) when bring_from_cache is true but the query has never produced a result — query.latest_query_data_id is None, so there is no cached QueryResult to return. The cached path intentionally never executes the underlying query.","triggerScenarios":"Calling get_query_results(user, query_id, bring_from_cache=True) (or in Python queries, adding the query id to the cached_query_ids argument) for a query that has not been run successfully yet, or whose results were deleted/archived.","commonSituations":"Newly created queries referenced by the results-loader before their first execution; cached results expired and were cleaned up by the periodic job; queries whose last run failed so latest_query_data was never set.","solutions":["Run the source query once successfully in the Redash UI so a cached result exists, then retry with bring_from_cache","Pass bring_from_cache=False (omit the id from cached_query_ids) so the runner executes the query live","If the result was deleted by retention/cleanup, re-execute the query and consider a longer result retention setting"],"exampleFix":"# before\nresults = get_query_results(user, qid, bring_from_cache=True)  # fails if never run\n# after\nresults = get_query_results(user, qid, bring_from_cache=query.latest_query_data_id is not None)","handlingStrategy":"fallback","validationCode":"query = models.Query.get_by_id(query_id)\nuse_cache = bring_from_cache and query.latest_query_data_id is not None\nresults = get_query_results(user, query_id, use_cache)","typeGuard":null,"tryCatchPattern":"try:\n    results = get_query_results(user, qid, True)\nexcept Exception as e:\n    if 'No cached result' in str(e):\n        results = get_query_results(user, qid, False)  # execute live\n    else:\n        raise","preventionTips":["Schedule source queries (alerts/refresh) so a cached result always exists","Check latest_query_data_id before choosing the cached path","Treat cache-miss as an automatic trigger to run live rather than an error"],"tags":["redash","cache","query-results","cache-miss"],"backgroundTag":"cache-miss","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}