langgenius/dify · error · NotFound

Dataset not found.

Error message

Dataset not found.

What it means

Flask NotFound (HTTP 404) raised at data_source.py:255 in DataSourceNotionListApi.get when req_data.dataset_id is truthy but DatasetService.get_dataset(req_data.dataset_id, session) returns None. The caller is trying to list Notion pages for import into an existing dataset, but that dataset does not exist (or is not visible to this caller via get_dataset).

Source

Thrown at api/controllers/console/datasets/data_source.py:255

        session: Session,
        current_tenant_id: str,
        current_user: Account,
    ) -> tuple[dict[str, Any], int]:
        datasource_provider_service = DatasourceProviderService()
        credential = datasource_provider_service.get_datasource_credentials(
            tenant_id=current_tenant_id,
            credential_id=req_data.credential_id,
            provider="notion_datasource",
            plugin_id="langgenius/notion_datasource",
        )
        if not credential:
            raise NotFound("Credential not found.")
        exist_page_ids = []
        # import notion in the exist dataset
        if req_data.dataset_id:
            dataset = DatasetService.get_dataset(req_data.dataset_id, session)
            if not dataset:
                raise NotFound("Dataset not found.")
            if dataset.data_source_type != "notion_import":
                raise ValueError("Dataset is not notion type.")

            documents = session.scalars(
                select(Document).where(
                    Document.dataset_id == req_data.dataset_id,
                    Document.tenant_id == current_tenant_id,
                    Document.data_source_type == "notion_import",
                    Document.enabled.is_(True),
                )
            ).all()
            if documents:
                for document in documents:
                    data_source_info = json.loads(document.data_source_info)
                    exist_page_ids.append(data_source_info["notion_page_id"])
        # get all authorized pages
        from core.datasource.datasource_manager import DatasourceManager

View on GitHub (pinned to ef8544b173)

Solutions

  1. Re-fetch the datasets list for the current workspace and use a valid dataset_id, or omit dataset_id to import into a new dataset.
  2. Confirm the user's current tenant actually owns the dataset (cross-tenant ids return None).
  3. Close and reopen the import wizard so the UI carries a fresh dataset_id.
  4. Handle the 404 in the client by falling back to the 'create new dataset' flow.
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the dataset exists in the current workspace before importing.
const datasets = await listDatasets();
if (datasetId && !datasets.some(d => d.id === datasetId)) {
  throw new Error('dataset_id not found — clear it to create a new dataset');
}

Type guard

function datasetInWorkspace(d: {id: string}, id: string): boolean { return d.id === id; }

Try / catch

try {
  await listNotionPages(credentialId, datasetId);
} catch (e) {
  if (e.status === 404 && /Dataset not found/i.test(e.message)) { clearDatasetId(); }
  else throw e;
}

Prevention

When it happens

Trigger: GET /console/api/data-source/notion/pre-import/pages?credential_id=<id>&dataset_id=<id> where dataset_id does not match any Dataset row (deleted, wrong workspace, typo). The credential was valid (passed the prior check) but the target dataset is gone.

Common situations: Dataset was deleted while the import wizard was open; user switched workspaces mid-flow; dataset_id copied incorrectly; or the dataset belongs to a different tenant and get_dataset scopes it out.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/cf6a708a6578cc80. Report an issue: GitHub.