{"record":{"id":"de1040c09f572d0d","repo":"apache/superset","slug":"datasource-value-is-neither-id-or-uuid","errorCode":null,"errorMessage":"Datasource value is neither id or uuid","messagePattern":"Datasource value is neither id or uuid","errorType":"exception","errorClass":"DatasourceValueIsIncorrect","httpStatus":422,"severity":"error","filePath":"superset/daos/datasource.py","lineNumber":78,"sourceCode":"        datasource_type: Union[DatasourceType, str],\n        database_id_or_uuid: int | str,\n    ) -> Datasource:\n        if datasource_type not in cls.sources:\n            raise DatasourceTypeNotSupportedError()\n\n        model = cls.sources[datasource_type]\n\n        if str(database_id_or_uuid).isdigit():\n            filter = model.id == int(database_id_or_uuid)\n        else:\n            try:\n                uuid.UUID(str(database_id_or_uuid))  # uuid validation\n                filter = model.uuid == database_id_or_uuid\n            except ValueError as err:\n                logger.warning(\n                    \"database_id_or_uuid %s isn't valid uuid\", database_id_or_uuid\n                )\n                raise DatasourceValueIsIncorrect() from err\n\n        datasource = (\n            db.session.query(cls.sources[datasource_type]).filter(filter).one_or_none()\n        )\n\n        if not datasource:\n            logger.warning(\n                \"Datasource not found datasource_type: %s, database_id_or_uuid: %s\",\n                datasource_type,\n                database_id_or_uuid,\n            )\n            raise DatasourceNotFound()\n\n        return datasource\n\n    @staticmethod\n    def build_dataset_query(\n        name_filter: str | None,","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/daos/datasource.py#L60-L96","documentation":"Raised by DatasourceDAO.get_datasource when database_id_or_uuid is neither an all-digit string (integer id) nor a parseable UUID. The DAO first tries str(...).isdigit() for the integer-id branch, then uuid.UUID() validation for the uuid branch; a ValueError from uuid.UUID triggers DatasourceValueIsIncorrect (HTTP 422) with the offending value logged as a warning. Note the check is strict: any non-digit, non-UUID string such as a dataset uid or a name is rejected here.","triggerScenarios":"Passing a value like 'abc', '12 3', an empty string, or a Superset 'uid' (short base62 identifier used in dashboards) as database_id_or_uuid; passing a UUID with invalid characters or wrong hyphenation; passing a float like '1.0' (the dot makes isdigit() false and UUID parsing fail).","commonSituations":"Confusing dataset identifiers: this DAO method wants a DATABASE integer id or UUID, but callers feed it a datasource uid from an imported dashboard JSON; locale-formatted numbers with separators; trailing whitespace or newline in values read from files or URLs.","solutions":["Pass either a plain integer id as a string/digit ('42') or a canonical UUID string ('550e8400-e29b-41d4-a716-446655440000').","Strip and validate the identifier client-side with str.isdigit() or a UUID regex before calling get_datasource.","If you actually hold a dashboard 'uid' or datasource uid, resolve it through the appropriate dataset/SavedQuery API first and pass that model's id/uuid here.","Check for invisible characters (whitespace, BOM) when the value originates from CSV/JSON import pipelines."],"exampleFix":"# before\nDatasourceDAO.get_datasource('SL', 'ds_uid_Xy12')  # not digits, not a UUID -> 422\n\n# after\nDatasourceDAO.get_datasource('SL', '550e8400-e29b-41d4-a716-446655440000')  # valid UUID\nDatasourceDAO.get_datasource('SL', '42')  # valid integer id","handlingStrategy":"validation","validationCode":"import uuid\n\ndef is_valid_id_or_uuid(value: int | str) -> bool:\n    s = str(value).strip()\n    return s.isdigit() or _is_uuid(s)\n\ndef _is_uuid(s: str) -> bool:\n    try:\n        uuid.UUID(s)\n        return True\n    except ValueError:\n        return False","typeGuard":"def is_int_id_or_uuid(v: object) -> TypeGuard[str]:\n    s = str(v)\n    if s.isdigit():\n        return True\n    try:\n        uuid.UUID(s)\n        return True\n    except ValueError:\n        return False","tryCatchPattern":"from superset.daos.exceptions import DatasourceValueIsIncorrect\ntry:\n    ds = DatasourceDAO.get_datasource(ds_type, db_ref)\nexcept DatasourceValueIsIncorrect:\n    # 422: identifier is neither digits nor a UUID — fix the caller's identifier source\n    return bad_request('database_id_or_uuid must be an integer id or a UUID')","preventionTips":["Normalize identifiers early: strip whitespace and reject values that are neither digits nor canonical UUIDs.","Never feed dashboard 'uid' strings into APIs that document id/uuid parameters.","Validate UUIDs with uuid.UUID() before persisting or forwarding them."],"tags":["dao","datasource","uuid","validation"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}