getredash/redash · error · Exception

Wrong data source name/id: %s.

Error message

Wrong data source name/id: %s.

What it means

_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).

Source

Thrown at redash/query_runner/python.py:223

        :result dict: The result dict
        :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.
        """
        if "rows" not in result:
            result["rows"] = []

        result["rows"].append(values)

    def _get_data_source(self, data_source_name_or_id, access_level):
        user = self._get_current_user()

        try:
            data_sources = models.DataSource.query.filter(models.DataSource.org_id == user.org_id)
            if isinstance(data_source_name_or_id, int):
                data_source = data_sources.filter(models.DataSource.id == data_source_name_or_id).one()
            else:
                data_source = data_sources.filter(models.DataSource.name == data_source_name_or_id).one()
        except (models.NoResultFound, MultipleResultsFound):
            raise Exception("Wrong data source name/id: %s." % data_source_name_or_id)

        if not has_access(data_source, user, access_level):
            raise Exception("You do not have access to data source: %s." % data_source_name_or_id)

        return data_source

    def execute_query(self, data_source_name_or_id, query, result_type=None):
        """Run query from specific data source.

        Parameters:
        :data_source_name_or_id string|integer: Name or ID of the data source
        :query string: Query to run
        """
        data_source = self._get_data_source(data_source_name_or_id, not_view_only)

        data, error = data_source.query_runner.run_query(query, self._current_user)
        if error is not None:
            raise Exception(error)

View on GitHub (pinned to ca79fe988d)

Solutions

  1. Check the exact data source name under Settings > Data Sources in the same Redash instance/org
  2. Prefer passing the numeric data source id as an int to avoid duplicate-name ambiguity
  3. Rename or remove duplicate-named data sources so name lookup is unique
  4. Verify you're pointing at the right instance (API URL/host)

Example fix

# before
execute_query('Sales DB', 'SELECT 1')  # renamed to 'SalesDB'
# after
execute_query(42, 'SELECT 1')  # numeric id from the data source list
Defensive patterns

Strategy: validation

Validate before calling

from redash import models
def resolve_ds(name_or_id, org):
    q = models.DataSource.query.filter(models.DataSource.org_id == org.id)
    if isinstance(name_or_id, int):
        return q.filter(models.DataSource.id == name_or_id).first()
    matches = q.filter(models.DataSource.name == name_or_id).all()
    return matches[0] if len(matches) == 1 else None

Type guard

def ds_ref_is_safe(ref) -> bool:
    # int ids are unambiguous; names must be unique in the org
    return isinstance(ref, int) or (isinstance(ref, str) and name_unique_in_org(ref))

Try / catch

try:
    ds = _get_data_source(ref, user, access)
except Exception as e:
    if 'Wrong data source name/id' in str(e):
        ref = lookup_fresh_id(ref); ds = _get_data_source(ref, user, access)

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of getredash/redash@ca79fe988d (2026-08-28). Data as JSON: /api/errors/fb48e976c815524a. Report an issue: GitHub.