{"record":{"id":"5376f5f82ee1ea7c","repo":"apache/superset","slug":"datasource-does-not-exist-5376f5","errorCode":null,"errorMessage":"Datasource does not exist","messagePattern":"Datasource does not exist","errorType":"validation","errorClass":"DatasourceNotFoundValidationError","httpStatus":404,"severity":"error","filePath":"superset/commands/utils.py","lineNumber":206,"sourceCode":"\n    if include_viewers and hasattr(model, \"viewers\"):\n        try:\n            properties[\"viewers\"] = compute_subject_list(\n                model.viewers,\n                properties.get(\"viewers\"),\n                field_name=\"viewers\",\n            )\n        except ValidationError as ex:\n            exceptions.append(ex)\n\n\ndef get_datasource_by_id(datasource_id: int, datasource_type: str) -> BaseDatasource:\n    try:\n        return DatasourceDAO.get_datasource(\n            DatasourceType(datasource_type), datasource_id\n        )\n    except DatasourceNotFound as ex:\n        raise DatasourceNotFoundValidationError() from ex\n\n\ndef validate_tags(\n    object_type: ObjectType,\n    current_tags: list[Tag],\n    new_tag_ids: Optional[list[int]],\n) -> None:\n    \"\"\"\n    Helper function for update commands, to validate the tags list. Users\n    with `can_write` on `Tag` are allowed to both create new tags and manage\n    tag association with objects. Users with `can_tag` on `object_type` are\n    only allowed to manage existing existing tags' associations with the object.\n\n    :param current_tags: list of current tags\n    :param new_tag_ids: list of tags specified in the update payload\n    \"\"\"\n\n    # `tags` not part of the update payload","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/utils.py#L188-L224","documentation":"get_datasource_by_id wraps DatasourceDAO.get_datasource and converts DatasourceNotFound into DatasourceNotFoundValidationError. It resolves a datasource by (id, type) where type must be a valid DatasourceType (e.g. 'table' for datasets, 'query'); if either the type is invalid or the dataset row is missing, the validation error is raised.","triggerScenarios":"Creating/updating charts, examples, or tags that reference a datasource_id with a missing or misspelled datasource_type; importing a chart whose dataset was not imported; dataset deleted between chart load and save.","commonSituations":"Chart import/export between instances where the target lacks the dataset; typos like datasource_type='dataset' instead of 'table'; datasets dropped during a cleanup while charts still reference them.","solutions":["Check the dataset exists: GET /api/v1/dataset/<id> before referencing it.","Use the exact DatasourceType value expected by the API ('table', not 'dataset').","When importing bundles, import/export datasets together with charts so references resolve."],"exampleFix":"# before\nchart = {\"datasource_id\": 7, \"datasource_type\": \"dataset\"}\n\n# after\nchart = {\"datasource_id\": 7, \"datasource_type\": \"table\"}  # verify via GET /api/v1/dataset/7","handlingStrategy":"validation","validationCode":"from superset.daos.datasource import DatasourceDAO\nfrom superset.common.db_query_status import DatasourceType  # or superset.connectors\ntry:\n    ds = DatasourceDAO.get_datasource(DatasourceType(datasource_type), datasource_id)\nexcept Exception:\n    ds = None\nif ds is None:\n    raise LookupError(\"datasource missing or bad type\")","typeGuard":null,"tryCatchPattern":"try:\n    get_datasource_by_id(datasource_id, datasource_type)\nexcept DatasourceNotFoundValidationError:\n    sync_or_import_dataset()","preventionTips":["Use exact DatasourceType strings ('table')","Import datasets alongside charts"],"tags":["datasource","dataset","not-found","validation","backend"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}