langgenius/dify · error · ValueError

Dataset is not notion type.

Error message

Dataset is not notion type.

What it means

Raised as a ValueError when a caller asks the Notion datasource import endpoint to add pages into an existing dataset whose data_source_type is not 'notion_import'. The controller loads the dataset by id, then asserts its type matches Notion before re-using the existing page-id list. The mismatch means the target knowledge base was created from a different source (upload_file, website_crawl, external) and cannot accept Notion pages.

Source

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

        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

        datasource_runtime = DatasourceManager.get_datasource_runtime(
            provider_id="langgenius/notion_datasource/notion_datasource",

View on GitHub (pinned to ef8544b173)

Solutions

  1. Send a request without dataset_id (or null) to create a new Notion dataset instead of importing into an existing one.
  2. If importing into an existing dataset, verify via GET /datasets/{id} that data_source_type == 'notion_import' before calling the Notion import endpoint.
  3. Fix the client so it only passes a Notion-origin dataset_id in the Notion import flow.

Example fix

// before
fetch('/console/api/datasets/notion', { method: 'POST', body: JSON.stringify({ dataset_id: fileDatasetId, ... }) })
// after
const ds = await fetch(`/console/api/datasets/${fileDatasetId}`).then(r => r.json())
if (ds.data_source_type !== 'notion_import') { delete payload.dataset_id }
fetch('/console/api/datasets/notion', { method: 'POST', body: JSON.stringify(payload) })
Defensive patterns

Strategy: validation

Validate before calling

# Before calling the Notion import endpoint with an existing dataset_id:
from api.services.dataset_service import DatasetService
from sqlalchemy.orm import Session

def can_import_notion_into(dataset_id: str, tenant_id: str, session: Session) -> bool:
    ds = DatasetService.get_dataset(dataset_id, session)
    return ds is not None and ds.tenant_id == tenant_id and ds.data_source_type == "notion_import"

Type guard

def is_notion_dataset(ds) -> bool:
    return getattr(ds, "data_source_type", None) == "notion_import"

Try / catch

try:
    resp = notion_import(payload)
except ValueError as e:
    if "not notion type" in str(e):
        payload.pop("dataset_id", None)  # fall back to creating a new dataset
        resp = notion_import(payload)
    else:
        raise

Prevention

When it happens

Trigger: POST to the Notion datasource API (data_source.py around line 240) with a req_data.dataset_id that points to a dataset created via upload_file, website_crawl, or an external provider. The check at line 256 (dataset.data_source_type != 'notion_import') fires before the Notion page sync runs.

Common situations: Frontend bug reusing a dataset_id from the wrong source type in the Notion import wizard; migrating/importing into a knowledge base that was originally built from file uploads; stale client state sending an old dataset_id after the user switched source tabs.

Related errors


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