{"record":{"id":"c7edc4165c8bdbec","repo":"langgenius/dify","slug":"credential-not-found","errorCode":null,"errorMessage":"Credential not found.","messagePattern":"Credential not found\\.","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"api/controllers/console/datasets/data_source.py","lineNumber":249,"sourceCode":"    @with_current_tenant_id\n    @with_session(write=False)\n    @model_validate(DataSourceNotionListQuery)\n    def get(\n        self,\n        req_data: DataSourceNotionListQuery,\n        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:","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/data_source.py#L231-L267","documentation":"Flask NotFound (HTTP 404) raised at data_source.py:249 in DataSourceNotionListApi.get (GET /data-source/notion/pre-import/pages) when DatasourceProviderService.get_datasource_credentials returns a falsy value for the given credential_id, provider='notion_datasource', plugin_id='langgenius/notion_datasource'. The Notion OAuth credential for this tenant/credential_id does not exist (or was revoked) in the credentials store.","triggerScenarios":"GET /console/api/data-source/notion/pre-import/pages?credential_id=<id> where the credential_id is unknown, belongs to another tenant, or the Notion datasource credential was deleted/expired before this pre-import listing call.","commonSituations":"User opened the Notion import wizard with a stale credential_id (e.g. after re-authenticating Notion which created a new credential); credential store cleanup removed the old entry; or the plugin credential was never successfully saved.","solutions":["Re-authorize the Notion datasource to obtain a fresh credential_id, then use that id in the query.","List existing credentials for the tenant to find the current notion_datasource credential_id.","Confirm the plugin 'langgenius/notion_datasource' is installed and enabled; a missing plugin yields no credential.","Ensure the request is scoped to the tenant that owns the credential."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the credential exists before listing Notion pages.\nconst creds = await listDatasourceCredentials(currentTenantId);\nif (!creds.some(c => c.id === credentialId && c.provider === 'notion_datasource')) {\n  throw new Error('Re-authorize Notion to get a fresh credential_id');\n}","typeGuard":"function isNotionCredential(c: {provider: string; id: string}, id: string): boolean {\n  return c.provider === 'notion_datasource' && c.id === id;\n}","tryCatchPattern":"try {\n  await listNotionPages(credentialId);\n} catch (e) {\n  if (e.status === 404 && /Credential not found/i.test(e.message)) { reAuthNotion(); }\n  else throw e;\n}","preventionTips":["Re-authorize Notion when the wizard is reopened after a long gap.","Pass the credential_id returned by the most recent authorization.","Confirm the notion_datasource plugin is installed."],"tags":["datasets","notion","credentials","not-found","plugin"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}