{"record":{"id":"8caa3897f8779702","repo":"getredash/redash","slug":"query-id-s-does-not-exist","errorCode":null,"errorMessage":"Query id %s does not exist.","messagePattern":"Query id (.+?) does not exist\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/python.py","lineNumber":275,"sourceCode":"        data_source = self._get_data_source(data_source_name_or_id, view_only)\n        schema = data_source.query_runner.get_schema()\n        return schema\n\n    def get_query_result(self, query_id):\n        \"\"\"Get result of an existing query.\n\n        Parameters:\n        :query_id integer: ID of existing query\n        \"\"\"\n        user = self._get_current_user()\n\n        try:\n            query = models.Query.query.filter(\n                models.Query.id == query_id,\n                models.Query.org_id == user.org_id,\n            ).one()\n        except models.NoResultFound:\n            raise Exception(\"Query id %s does not exist.\" % query_id)\n\n        if query.data_source is None or not has_access(query.data_source, user, view_only):\n            raise Exception(\"You do not have access to query id %s.\" % query_id)\n\n        if query.latest_query_data is None:\n            raise Exception(\"Query does not have results yet.\")\n\n        if query.latest_query_data.data is None:\n            raise Exception(\"Query does not have results yet.\")\n\n        if query.latest_query_data.data_source is None or not has_access(\n            query.latest_query_data.data_source, user, view_only\n        ):\n            raise Exception(\"You do not have access to query id %s.\" % query_id)\n\n        return query.latest_query_data.data\n\n    def dataframe_to_result(self, result, df):","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/python.py#L257-L293","documentation":"get_query_result() loads a Query by id scoped to the current user's org; models.NoResultFound triggers this Exception. It means no query with that id exists in the user's organization — wrong id, deleted query, or a query belonging to a different org.","triggerScenarios":"Calling get_query_result(99999) with a nonexistent id; passing an id from another Redash instance; the query was deleted; or the id exists only in a different tenant org.","commonSituations":"Hard-coded query ids in shared Python queries breaking after deletion; copying queries between staging and production where ids differ; typo in the literal id.","solutions":["Look up the correct query id from the query URL (e.g. /queries/1234) in the same instance and org","If the query was deleted, restore it or update the Python query to use the replacement id","Avoid hard-coding ids; store them in variables/document where they can be updated once"],"exampleFix":"# before\nget_query_result(123)  # deleted\n# after\nget_query_result(456)  # current id from /queries/456","handlingStrategy":"validation","validationCode":"from redash import models\nq = models.Query.query.filter(models.Query.id == qid, models.Query.org_id == user.org_id).first()\nassert q is not None, f'query {qid} not found in this org'","typeGuard":null,"tryCatchPattern":"try:\n    get_query_result(qid)\nexcept Exception as e:\n    if 'does not exist' in str(e):\n        qid = find_query_by_name(name); get_query_result(qid)","preventionTips":["Reference queries by id captured from the URL at authoring time","Re-validate hard-coded ids after instance migrations/deletions"],"tags":["redash","python-runner","query-not-found","lookup"],"backgroundTag":"resource-not-found-by-name-or-id","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}