{"record":{"id":"cf6a708a6578cc80","repo":"langgenius/dify","slug":"dataset-not-found","errorCode":null,"errorMessage":"Dataset not found.","messagePattern":"Dataset not found\\.","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"api/controllers/console/datasets/data_source.py","lineNumber":255,"sourceCode":"        session: Session,\n        current_tenant_id: str,\n        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","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/data_source.py#L237-L273","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Confirm the user's current tenant actually owns the dataset (cross-tenant ids return None).","Close and reopen the import wizard so the UI carries a fresh dataset_id.","Handle the 404 in the client by falling back to the 'create new dataset' flow."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Confirm the dataset exists in the current workspace before importing.\nconst datasets = await listDatasets();\nif (datasetId && !datasets.some(d => d.id === datasetId)) {\n  throw new Error('dataset_id not found — clear it to create a new dataset');\n}","typeGuard":"function datasetInWorkspace(d: {id: string}, id: string): boolean { return d.id === id; }","tryCatchPattern":"try {\n  await listNotionPages(credentialId, datasetId);\n} catch (e) {\n  if (e.status === 404 && /Dataset not found/i.test(e.message)) { clearDatasetId(); }\n  else throw e;\n}","preventionTips":["Refresh the datasets list when opening the import wizard.","Omit dataset_id when the user wants to create a new dataset.","Re-check ownership after switching workspaces."],"tags":["datasets","notion","dataset","not-found","tenant-scoped"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}