apache/superset · error · DatasourceNotFoundValidationError
Datasource does not exist
Error message
Datasource does not exist
What it means
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.
Source
Thrown at superset/commands/utils.py:206
if include_viewers and hasattr(model, "viewers"):
try:
properties["viewers"] = compute_subject_list(
model.viewers,
properties.get("viewers"),
field_name="viewers",
)
except ValidationError as ex:
exceptions.append(ex)
def get_datasource_by_id(datasource_id: int, datasource_type: str) -> BaseDatasource:
try:
return DatasourceDAO.get_datasource(
DatasourceType(datasource_type), datasource_id
)
except DatasourceNotFound as ex:
raise DatasourceNotFoundValidationError() from ex
def validate_tags(
object_type: ObjectType,
current_tags: list[Tag],
new_tag_ids: Optional[list[int]],
) -> None:
"""
Helper function for update commands, to validate the tags list. Users
with `can_write` on `Tag` are allowed to both create new tags and manage
tag association with objects. Users with `can_tag` on `object_type` are
only allowed to manage existing existing tags' associations with the object.
:param current_tags: list of current tags
:param new_tag_ids: list of tags specified in the update payload
"""
# `tags` not part of the update payloadView on GitHub (pinned to f4587218dd)
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.
Example fix
# before
chart = {"datasource_id": 7, "datasource_type": "dataset"}
# after
chart = {"datasource_id": 7, "datasource_type": "table"} # verify via GET /api/v1/dataset/7 Defensive patterns
Strategy: validation
Validate before calling
from superset.daos.datasource import DatasourceDAO
from superset.common.db_query_status import DatasourceType # or superset.connectors
try:
ds = DatasourceDAO.get_datasource(DatasourceType(datasource_type), datasource_id)
except Exception:
ds = None
if ds is None:
raise LookupError("datasource missing or bad type") Try / catch
try:
get_datasource_by_id(datasource_id, datasource_type)
except DatasourceNotFoundValidationError:
sync_or_import_dataset() Prevention
- Use exact DatasourceType strings ('table')
- Import datasets alongside charts
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Datasource does not exist
- Theme not found.
- Theme not found.
- Tag ID {tag_id} not found
- Drill to detail is not available for this datasource type.
AI-assisted analysis of apache/superset@f4587218dd (2026-08-14).
Data as JSON: /api/errors/5376f5f82ee1ea7c.
Report an issue: GitHub.