Skip to content

armgit / dify

Public Imported from GitHub
0

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.

fix: join all rich_text/title segments in Notion database extraction (#42050)

Harsh Kashyap6e91ee2694d9
diff --git a/api/core/rag/extractor/notion_extractor.py b/api/core/rag/extractor/notion_extractor.py
index 99f2362fe68..f0c30b36d7e 100644
--- a/api/core/rag/extractor/notion_extractor.py
+++ b/api/core/rag/extractor/notion_extractor.py
@@ -135,10 +135,9 @@ class NotionExtractor(BaseExtractor):
for multi_select in multi_select_list:
value.append(multi_select["name"])
elif type in {"rich_text", "title"}:
- if len(property_value[type]) > 0:
- value = property_value[type][0]["plain_text"]
- else:
- value = ""
+ # Notion splits formatted text into multiple segments;
+ # join them all so no part of the value is dropped.
+ value = "".join(segment.get("plain_text", "") for segment in property_value[type])
elif type in {"select", "status"}:
if property_value[type]:
value = property_value[type]["name"]
diff --git a/api/tests/unit_tests/core/rag/extractor/test_notion_extractor.py b/api/tests/unit_tests/core/rag/extractor/test_notion_extractor.py
index 4527bf2a4e2..56c9e254e38 100644
--- a/api/tests/unit_tests/core/rag/extractor/test_notion_extractor.py
+++ b/api/tests/unit_tests/core/rag/extractor/test_notion_extractor.py
@@ -196,6 +196,49 @@ class TestNotionDatabase:
assert "Row Page URL:https://notion.so/page-1" in content
assert mock_post.call_count == 2
+ def test_get_notion_database_data_joins_all_rich_text_segments(self, mocker: MockerFixture):
+ """Formatted text arrives as multiple segments; all of them must be kept."""
+ extractor = notion_extractor.NotionExtractor(
+ notion_workspace_id="ws",
+ notion_obj_id="obj",
+ notion_page_type="database",
+ tenant_id="tenant",
+ notion_access_token="token",
+ )
+
+ page = {
+ "results": [
+ {
+ "properties": {
+ "title_prop": {
+ "type": "title",
+ "title": [{"plain_text": "Hello "}, {"plain_text": "world"}],
+ },
+ "rich": {
+ "type": "rich_text",
+ "rich_text": [
+ {"plain_text": "first "},
+ {"plain_text": "second"},
+ {"plain_text": " third"},
+ ],
+ },
+ },
+ "url": "https://notion.so/page-1",
+ }
+ ],
+ "has_more": False,
+ "next_cursor": None,
+ }
+
+ mocker.patch("httpx.post", return_value=_mock_response(page))
+
+ docs = extractor._get_notion_database_data("db-1")
+
+ assert len(docs) == 1
+ content = docs[0].page_content
+ assert "rich:first second third" in content
+ assert "title_prop:Hello world" in content
+
def test_get_notion_database_data_handles_missing_results_and_empty_content(self, mocker: MockerFixture):
extractor = notion_extractor.NotionExtractor(
notion_workspace_id="ws",