{"record":{"id":"fb48e976c815524a","repo":"getredash/redash","slug":"wrong-data-source-name-id-s","errorCode":null,"errorMessage":"Wrong data source name/id: %s.","messagePattern":"Wrong data source name/id: (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/python.py","lineNumber":223,"sourceCode":"        :result dict: The result dict\n        :values dict: One row of result in dict. The key should be one of the column names. The value is the value of the column in this row.\n        \"\"\"\n        if \"rows\" not in result:\n            result[\"rows\"] = []\n\n        result[\"rows\"].append(values)\n\n    def _get_data_source(self, data_source_name_or_id, access_level):\n        user = self._get_current_user()\n\n        try:\n            data_sources = models.DataSource.query.filter(models.DataSource.org_id == user.org_id)\n            if isinstance(data_source_name_or_id, int):\n                data_source = data_sources.filter(models.DataSource.id == data_source_name_or_id).one()\n            else:\n                data_source = data_sources.filter(models.DataSource.name == data_source_name_or_id).one()\n        except (models.NoResultFound, MultipleResultsFound):\n            raise Exception(\"Wrong data source name/id: %s.\" % data_source_name_or_id)\n\n        if not has_access(data_source, user, access_level):\n            raise Exception(\"You do not have access to data source: %s.\" % data_source_name_or_id)\n\n        return data_source\n\n    def execute_query(self, data_source_name_or_id, query, result_type=None):\n        \"\"\"Run query from specific data source.\n\n        Parameters:\n        :data_source_name_or_id string|integer: Name or ID of the data source\n        :query string: Query to run\n        \"\"\"\n        data_source = self._get_data_source(data_source_name_or_id, not_view_only)\n\n        data, error = data_source.query_runner.run_query(query, self._current_user)\n        if error is not None:\n            raise Exception(error)","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/python.py#L205-L241","documentation":"_get_data_source() looks up a DataSource by id (int) or name (string) scoped to the current user's org. It raises this when the lookup raises NoResultFound or MultipleResultsFound: no data source with that name/id exists in the org, or the name matches several data sources (duplicate names).","triggerScenarios":"Calling execute_query('my_ds', ...) / get_source_schema where 'my_ds' is deleted, renamed, spelled with different case, exists in another org, or where two data sources share the name (name lookup uses .one(), which fails on duplicates).","commonSituations":"Data source renamed or deleted after the query was written; environment differences (staging vs prod names); multiple data sources created with the same friendly name; passing a string id \"1\" (treated as name) instead of int 1.","solutions":["Check the exact data source name under Settings > Data Sources in the same Redash instance/org","Prefer passing the numeric data source id as an int to avoid duplicate-name ambiguity","Rename or remove duplicate-named data sources so name lookup is unique","Verify you're pointing at the right instance (API URL/host)"],"exampleFix":"# before\nexecute_query('Sales DB', 'SELECT 1')  # renamed to 'SalesDB'\n# after\nexecute_query(42, 'SELECT 1')  # numeric id from the data source list","handlingStrategy":"validation","validationCode":"from redash import models\ndef resolve_ds(name_or_id, org):\n    q = models.DataSource.query.filter(models.DataSource.org_id == org.id)\n    if isinstance(name_or_id, int):\n        return q.filter(models.DataSource.id == name_or_id).first()\n    matches = q.filter(models.DataSource.name == name_or_id).all()\n    return matches[0] if len(matches) == 1 else None","typeGuard":"def ds_ref_is_safe(ref) -> bool:\n    # int ids are unambiguous; names must be unique in the org\n    return isinstance(ref, int) or (isinstance(ref, str) and name_unique_in_org(ref))","tryCatchPattern":"try:\n    ds = _get_data_source(ref, user, access)\nexcept Exception as e:\n    if 'Wrong data source name/id' in str(e):\n        ref = lookup_fresh_id(ref); ds = _get_data_source(ref, user, access)","preventionTips":["Reference data sources by numeric id, not name","Keep data source names unique per org","Centralize ids in one config variable in the script"],"tags":["redash","python-runner","data-source","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"}