Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix: handle missing `credential_id` (#30051)
Rhysa5309bee256f
diff --git a/api/controllers/console/datasets/datasets_document.py b/api/controllers/console/datasets/datasets_document.pyindex 6145da31a55..e94768f9855 100644--- a/api/controllers/console/datasets/datasets_document.py+++ b/api/controllers/console/datasets/datasets_document.py@@ -572,7 +572,7 @@ class DocumentBatchIndexingEstimateApi(DocumentResource):datasource_type=DatasourceType.NOTION,notion_info=NotionInfo.model_validate({- "credential_id": data_source_info["credential_id"],+ "credential_id": data_source_info.get("credential_id"),"notion_workspace_id": data_source_info["notion_workspace_id"],"notion_obj_id": data_source_info["notion_page_id"],"notion_page_type": data_source_info["type"],diff --git a/api/core/indexing_runner.py b/api/core/indexing_runner.pyindex 59de4f403da..f1b50f360b5 100644--- a/api/core/indexing_runner.py+++ b/api/core/indexing_runner.py@@ -396,7 +396,7 @@ class IndexingRunner:datasource_type=DatasourceType.NOTION,notion_info=NotionInfo.model_validate({- "credential_id": data_source_info["credential_id"],+ "credential_id": data_source_info.get("credential_id"),"notion_workspace_id": data_source_info["notion_workspace_id"],"notion_obj_id": data_source_info["notion_page_id"],"notion_page_type": data_source_info["type"],diff --git a/api/core/rag/extractor/notion_extractor.py b/api/core/rag/extractor/notion_extractor.pyindex e87ab383494..372af8fd941 100644--- a/api/core/rag/extractor/notion_extractor.py+++ b/api/core/rag/extractor/notion_extractor.py@@ -48,13 +48,21 @@ class NotionExtractor(BaseExtractor):if notion_access_token:self._notion_access_token = notion_access_tokenelse:- self._notion_access_token = self._get_access_token(tenant_id, self._credential_id)- if not self._notion_access_token:+ try:+ self._notion_access_token = self._get_access_token(tenant_id, self._credential_id)+ except Exception as e:+ logger.warning(+ (+ "Failed to get Notion access token from datasource credentials: %s, "+ "falling back to environment variable NOTION_INTEGRATION_TOKEN"+ ),+ e,+ )integration_token = dify_config.NOTION_INTEGRATION_TOKENif integration_token is None:raise ValueError("Must specify `integration_token` or set environment variable `NOTION_INTEGRATION_TOKEN`."- )+ ) from eself._notion_access_token = integration_tokendiff --git a/api/tests/unit_tests/core/datasource/test_notion_provider.py b/api/tests/unit_tests/core/datasource/test_notion_provider.pyindex 9e7255bc3f3..e4bd7d3bdf9 100644--- a/api/tests/unit_tests/core/datasource/test_notion_provider.py+++ b/api/tests/unit_tests/core/datasource/test_notion_provider.py@@ -96,7 +96,7 @@ class TestNotionExtractorAuthentication:def test_init_with_integration_token_fallback(self, mock_get_token, mock_config, mock_document_model):"""Test NotionExtractor falls back to integration token when credential not found."""# Arrange- mock_get_token.return_value = None+ mock_get_token.side_effect = Exception("No credential id found")mock_config.NOTION_INTEGRATION_TOKEN = "integration-token-fallback"# Act@@ -105,7 +105,7 @@ class TestNotionExtractorAuthentication:notion_obj_id="page-456",notion_page_type="page",tenant_id="tenant-789",- credential_id="cred-123",+ credential_id=None,document_model=mock_document_model,)@@ -117,7 +117,7 @@ class TestNotionExtractorAuthentication:def test_init_missing_credentials_raises_error(self, mock_get_token, mock_config, mock_document_model):"""Test NotionExtractor raises error when no credentials available."""# Arrange- mock_get_token.return_value = None+ mock_get_token.side_effect = Exception("No credential id found")mock_config.NOTION_INTEGRATION_TOKEN = None# Act & Assert@@ -127,7 +127,7 @@ class TestNotionExtractorAuthentication:notion_obj_id="page-456",notion_page_type="page",tenant_id="tenant-789",- credential_id="cred-123",+ credential_id=None,document_model=mock_document_model,)assert "Must specify `integration_token`" in str(exc_info.value)