{"record":{"id":"e8b5839c46f1aedd","repo":"getredash/redash","slug":"failed-loading-results-for-query-id","errorCode":null,"errorMessage":"Failed loading results for query id {}.","messagePattern":"Failed loading results for query id (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/query_results.py","lineNumber":80,"sourceCode":"        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\n    for query in set(query_params):\n        results = get_query_results(user, query[0], False, query[1])\n        table_hash = hashlib.md5(\n            \"query_{query}_{hash}\".format(query=query[0], hash=query[1]).encode(), usedforsecurity=False\n        ).hexdigest()\n        table_name = \"query_{query_id}_{param_hash}\".format(query_id=query[0], param_hash=table_hash)\n        create_table(connection, table_name, results)\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/query_results.py#L62-L98","documentation":"Raised by get_query_results (redash/query_runner/query_results.py:80) when the non-cached path executes the query via query.data_source.query_runner.run_query and that runner returns a non-None error. It is a wrapper: the real cause is whatever made the underlying data source execution fail (SQL syntax, credentials, timeouts, network).","triggerScenarios":"Calling get_query_results with bring_from_cache=False where the source query fails at the data source: bad SQL, expired credentials, unreachable database, query timeout, or unsupported syntax.","commonSituations":"A results-loader Python query referencing a source query whose SQL recently broke after a schema change; data source password rotation; the source query runs fine interactively but the loader runs it as a different user hitting row-level restrictions.","solutions":["Open and execute the source query directly in Redash to see the underlying data source error","Fix that root cause (SQL, credentials, connectivity, timeout settings) — this exception carries no extra detail","If the source query is slow, raise its timeout or pre-schedule it and use bring_from_cache=True"],"exampleFix":"# before\nresults = get_query_results(user, qid, bring_from_cache=False)\n# after\ntry:\n    results = get_query_results(user, qid, bring_from_cache=False)\nexcept Exception as e:\n    logger.error('query %s failed: %s', qid, e)\n    results = get_query_results(user, qid, bring_from_cache=True)  # fall back to last good result","handlingStrategy":"fallback","validationCode":"results, err = query.data_source.query_runner.run_query(query_text, user)\nif err:\n    logger.warning('source query %s failed: %s', query_id, err)\n    # decide before calling get_query_results whether to proceed","typeGuard":null,"tryCatchPattern":"try:\n    results = get_query_results(user, qid, False)\nexcept Exception as e:\n    logger.error('loader failed for query %s: %s', qid, e)\n    results = get_query_results(user, qid, True)  # serve last good cached result","preventionTips":["Monitor the source query with an alert so failures surface before loaders break","Debug by running the source query directly to get the real error text","Wrap loader calls and fall back to cached results for read-only dashboards"],"tags":["redash","query-execution","wrapper-error"],"backgroundTag":"query-execution-failed","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}