{"record":{"id":"855922f8a7dcd86c","repo":"getredash/redash","slug":"no-cached-result-found-for-this-query","errorCode":null,"errorMessage":"No cached result found for this query.","messagePattern":"No cached result found for this query\\.","errorType":"http","errorClass":null,"httpStatus":404,"severity":"warning","filePath":"redash/handlers/query_results.py","lineNumber":328,"sourceCode":"        query_result = None\n        query = None\n\n        if query_result_id:\n            query_result = get_object_or_404(models.QueryResult.get_by_id_and_org, query_result_id, self.current_org)\n\n        if query_id is not None:\n            query = get_object_or_404(models.Query.get_by_id_and_org, query_id, self.current_org)\n\n            if query_result is None and query is not None and query.latest_query_data_id is not None:\n                query_result = get_object_or_404(\n                    models.QueryResult.get_by_id_and_org,\n                    query.latest_query_data_id,\n                    self.current_org,\n                )\n\n            if query is not None and query_result is not None and self.current_user.is_api_user():\n                if query.query_hash != query_result.query_hash:\n                    abort(404, message=\"No cached result found for this query.\")\n\n        if query_result:\n            require_access(query_result.data_source, self.current_user, view_only)\n\n            if isinstance(self.current_user, models.ApiUser):\n                event = {\n                    \"user_id\": None,\n                    \"org_id\": self.current_org.id,\n                    \"action\": \"api_get\",\n                    \"api_key\": self.current_user.name,\n                    \"file_type\": filetype,\n                    \"user_agent\": request.user_agent.string,\n                    \"ip\": request.remote_addr,\n                }\n\n                if query_id:\n                    event[\"object_type\"] = \"query\"\n                    event[\"object_id\"] = query_id","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/handlers/query_results.py#L310-L346","documentation":"Raised by QueryResultResource.get in redash/handlers/query_results.py when an API-key user (public/query API key) requests a cached result by id and the stored query_result's query_hash no longer matches the query's current query_hash — meaning the query text changed since that result was produced, so it is not a valid cached answer.","triggerScenarios":"GET /api/query_results/<result_id> with a query API key where the underlying query was edited after the result was generated (parameters or text change the hash).","commonSituations":"Embedding a live result link while the query evolves; fetching an old result id after the query was parameterized or its text updated.","solutions":["Re-execute the query to generate a fresh result matching the current hash, then fetch that result id.","If you need historical results regardless of text changes, authenticate as a user API key rather than a query key.","Keep parameter values stable between the execution that produced the result and the cached fetch."],"exampleFix":"# before\nresp = client.get('/api/query_results/999', headers={'Authorization': 'Key <query api key>'})\n\n# after\njob = client.post(f'/api/queries/{qid}/refresh', headers=user_headers)\nresp = client.get(f\"/api/jobs/{job['id']}\")  # then fetch new result id","handlingStrategy":"fallback","validationCode":"# execute the query fresh instead of relying on an old result id\njob = client.post(f'/api/queries/{qid}/refresh', headers=user_headers)","typeGuard":null,"tryCatchPattern":"try:\n    resp = client.get(f'/api/query_results/{rid}', headers=h)\nexcept HTTPError as e:\n    if e.response.status_code == 404 and 'cached result' in e.response.text:\n        resp = rerun_query_and_fetch(qid)\n    else:\n        raise","preventionTips":["Treat cached fetches as best-effort with a query-key auth; plan a rerun path.","Fetch the latest_query_data_id from the query object rather than persisting old result ids."],"tags":["redash","query-results","cache","not-found"],"backgroundTag":"stale-cache-mismatch","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}