{"record":{"id":"f7639acb22fc624d","repo":"apache/superset","slug":"dao-datasource-query-source-type-is-not-supported","errorCode":null,"errorMessage":"DAO datasource query source type is not supported","messagePattern":"DAO datasource query source type is not supported","errorType":"exception","errorClass":"DatasourceTypeNotSupportedError","httpStatus":422,"severity":"error","filePath":"superset/daos/datasource.py","lineNumber":64,"sourceCode":"    return value.replace(\"\\\\\", \"\\\\\\\\\").replace(\"%\", \"\\\\%\").replace(\"_\", \"\\\\_\")\n\n\nclass DatasourceDAO(BaseDAO[Datasource]):\n    sources: dict[Union[DatasourceType, str], type[Datasource]] = {\n        DatasourceType.TABLE: SqlaTable,\n        DatasourceType.QUERY: Query,\n        DatasourceType.SAVEDQUERY: SavedQuery,\n        DatasourceType.SEMANTIC_VIEW: SemanticView,\n    }\n\n    @classmethod\n    def get_datasource(\n        cls,\n        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        )","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/daos/datasource.py#L46-L82","documentation":"Raised by DatasourceDAO.get_datasource when the requested datasource_type is not a key in the DAO's `sources` registry, which only maps DatasourceType.SL (datasets), QUERY, SAVEDQUERY, and SEMANTIC_VIEW to ORM models. It is a DAOException with HTTP status 422. The method resolves a logical datasource type plus a database-side identifier to a concrete model instance, so an unregistered type cannot be resolved at all.","triggerScenarios":"Calling DatasourceDAO.get_datasource('SOME_TABLE_TYPE', db_id) with a type not in {SL, QUERY, SAVEDQUERY, SEMANTIC_VIEW}; passing a legacy or custom datasource type string (e.g. 'druid' on builds where it is not registered); sending a typo'd type query parameter through an API that forwards it verbatim to the DAO.","commonSituations":"Upgrades that rename or remove datasource types (e.g. Druid removal) while old clients or cached dashboards still send the old type; third-party plugins extending the datasource API surface without registering their model in cls.sources; frontend code constructing the type string from a stale enum.","solutions":["Pass one of the registered types: 'SL' for datasets, 'QUERY' for query results, 'SAVEDQUERY' for saved queries, or 'SEMANTIC_VIEW' for semantic views.","If you control the caller, log datasource_type before the call and diff it against DatasourceDAO.sources keys to catch typos or stale values.","If you are adding a custom datasource type, register its ORM model by extending the `sources` classvar mapping on DatasourceDAO rather than calling get_datasource with an unknown type.","On version upgrades, grep the release notes / UPDATING.md for removed datasource types and migrate stored references."],"exampleFix":"// before\nDatasourceDAO.get_datasource('druid', database_id)  # raises DatasourceTypeNotSupportedError (422)\n\n// after\nDatasourceDAO.get_datasource(DatasourceType.SL, database_id)  # registered in cls.sources","handlingStrategy":"validation","validationCode":"from superset.daos.datasource import DatasourceDAO\nfrom superset.models.core import DatasourceType  # or the enum's home module\n\ndef is_supported_datasource_type(ds_type: str) -> bool:\n    return ds_type in DatasourceDAO.sources","typeGuard":"def is_known_datasource_type(t: str) -> TypeGuard[str]:\n    from superset.daos.datasource import DatasourceDAO\n    return t in DatasourceDAO.sources","tryCatchPattern":"from superset.daos.exceptions import DatasourceTypeNotSupportedError\ntry:\n    ds = DatasourceDAO.get_datasource(ds_type, db_ref)\nexcept DatasourceTypeNotSupportedError:\n    # 422: caller sent an unregistered type; do not retry with same input\n    return bad_request(f'unsupported datasource type: {ds_type}')","preventionTips":["Construct datasource types from the DatasourceType enum instead of raw strings.","Pin the allowed set from DatasourceDAO.sources.keys() at startup and validate inbound API params against it.","After upgrades, check UPDATING.md for datasource-type removals before shipping clients that hardcode type strings."],"tags":["dao","datasource","validation","api-misuse"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}