{"record":{"id":"33548d68393d467d","repo":"langgenius/dify","slug":"dataset-is-not-notion-type","errorCode":null,"errorMessage":"Dataset is not notion type.","messagePattern":"Dataset is not notion type\\.","errorType":"exception","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"api/controllers/console/datasets/data_source.py","lineNumber":257,"sourceCode":"        current_user: Account,\n    ) -> tuple[dict[str, Any], int]:\n        datasource_provider_service = DatasourceProviderService()\n        credential = datasource_provider_service.get_datasource_credentials(\n            tenant_id=current_tenant_id,\n            credential_id=req_data.credential_id,\n            provider=\"notion_datasource\",\n            plugin_id=\"langgenius/notion_datasource\",\n        )\n        if not credential:\n            raise NotFound(\"Credential not found.\")\n        exist_page_ids = []\n        # import notion in the exist dataset\n        if req_data.dataset_id:\n            dataset = DatasetService.get_dataset(req_data.dataset_id, session)\n            if not dataset:\n                raise NotFound(\"Dataset not found.\")\n            if dataset.data_source_type != \"notion_import\":\n                raise ValueError(\"Dataset is not notion type.\")\n\n            documents = session.scalars(\n                select(Document).where(\n                    Document.dataset_id == req_data.dataset_id,\n                    Document.tenant_id == current_tenant_id,\n                    Document.data_source_type == \"notion_import\",\n                    Document.enabled.is_(True),\n                )\n            ).all()\n            if documents:\n                for document in documents:\n                    data_source_info = json.loads(document.data_source_info)\n                    exist_page_ids.append(data_source_info[\"notion_page_id\"])\n        # get all authorized pages\n        from core.datasource.datasource_manager import DatasourceManager\n\n        datasource_runtime = DatasourceManager.get_datasource_runtime(\n            provider_id=\"langgenius/notion_datasource/notion_datasource\",","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/data_source.py#L239-L275","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Send a request without dataset_id (or null) to create a new Notion dataset instead of importing into an existing one.","If importing into an existing dataset, verify via GET /datasets/{id} that data_source_type == 'notion_import' before calling the Notion import endpoint.","Fix the client so it only passes a Notion-origin dataset_id in the Notion import flow."],"exampleFix":"// before\nfetch('/console/api/datasets/notion', { method: 'POST', body: JSON.stringify({ dataset_id: fileDatasetId, ... }) })\n// after\nconst ds = await fetch(`/console/api/datasets/${fileDatasetId}`).then(r => r.json())\nif (ds.data_source_type !== 'notion_import') { delete payload.dataset_id }\nfetch('/console/api/datasets/notion', { method: 'POST', body: JSON.stringify(payload) })","handlingStrategy":"validation","validationCode":"# Before calling the Notion import endpoint with an existing dataset_id:\nfrom api.services.dataset_service import DatasetService\nfrom sqlalchemy.orm import Session\n\ndef can_import_notion_into(dataset_id: str, tenant_id: str, session: Session) -> bool:\n    ds = DatasetService.get_dataset(dataset_id, session)\n    return ds is not None and ds.tenant_id == tenant_id and ds.data_source_type == \"notion_import\"","typeGuard":"def is_notion_dataset(ds) -> bool:\n    return getattr(ds, \"data_source_type\", None) == \"notion_import\"","tryCatchPattern":"try:\n    resp = notion_import(payload)\nexcept ValueError as e:\n    if \"not notion type\" in str(e):\n        payload.pop(\"dataset_id\", None)  # fall back to creating a new dataset\n        resp = notion_import(payload)\n    else:\n        raise","preventionTips":["Only pass dataset_id in the Notion flow when it came from a Notion-origin dataset.","GET /datasets/{id} and assert data_source_type == 'notion_import' before importing.","Keep dataset_id selection coupled to the active source-type tab in the UI."],"tags":["dataset","notion","data-source","validation","value-error"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}