RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Fix email and presentation parsers treating an empty upload as a missing binary (#18712)
Yash Raj Pandeyb003502917b2
diff --git a/rag/app/email.py b/rag/app/email.pyindex 90c926e62e..bde97b207c 100644--- a/rag/app/email.py+++ b/rag/app/email.py@@ -51,7 +51,7 @@ def chunk(main_res = []attachment_res = []- if binary:+ if binary is not None:with io.BytesIO(binary) as buffer:msg = BytesParser(policy=policy.default).parse(buffer)else:diff --git a/rag/app/presentation.py b/rag/app/presentation.pyindex ef2c77fe75..b8f2c668f0 100644--- a/rag/app/presentation.py+++ b/rag/app/presentation.py@@ -40,7 +40,7 @@ class Pdf(PdfParser):def __call__(self, filename, binary=None, from_page=0, to_page=MAXIMUM_PAGE_NUMBER, zoomin=3, callback=None, **kwargs):# 1. OCRcallback(msg="OCR started")- self.__images__(filename if not binary else binary, zoomin, from_page, to_page, callback)+ self.__images__(filename if binary is None else binary, zoomin, from_page, to_page, callback)# 2. Layout Analysiscallback(msg="Layout Analysis")@@ -118,7 +118,7 @@ class Pdf(PdfParser):class PlainPdf(PlainParser):def __call__(self, filename, binary=None, from_page=0, to_page=MAXIMUM_PAGE_NUMBER, callback=None, **kwargs):- self.pdf = pdf2_read(filename if not binary else BytesIO(binary))+ self.pdf = pdf2_read(filename if binary is None else BytesIO(binary))page_txt = []for page in self.pdf.pages[from_page:to_page]:page_txt.append(page.extract_text())@@ -141,7 +141,7 @@ def chunk(filename, binary=None, from_page=0, to_page=MAXIMUM_PAGE_NUMBER, lang=if re.search(r"\.pptx?$", filename, re.IGNORECASE):try:ppt_parser = RAGFlowPptParser()- for pn, txt in enumerate(ppt_parser(filename if not binary else binary, from_page, MAXIMUM_PAGE_NUMBER, callback)):+ for pn, txt in enumerate(ppt_parser(filename if binary is None else binary, from_page, MAXIMUM_PAGE_NUMBER, callback)):d = copy.deepcopy(doc)pn += from_paged["doc_type_kwd"] = "image"@@ -165,7 +165,7 @@ def chunk(filename, binary=None, from_page=0, to_page=MAXIMUM_PAGE_NUMBER, lang=logging.warning(f"{error_msg} for {filename}.")raise NotImplementedError(error_msg)- if binary:+ if binary is not None:binary_data = binaryelse:with open(filename, "rb") as f:diff --git a/test/unit_test/rag/app/test_email_empty_binary.py b/test/unit_test/rag/app/test_email_empty_binary.pynew file mode 100644index 0000000000..ae8a0587c3--- /dev/null+++ b/test/unit_test/rag/app/test_email_empty_binary.py@@ -0,0 +1,35 @@+#+# Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#++from __future__ import annotations++import pytest++from rag.app import email++[email protected](autouse=True)+def _stub_rag_tokenizer(monkeypatch):+ def fake_tokenize(text):+ return str(text)++ monkeypatch.setattr("rag.nlp.rag_tokenizer.tokenize", fake_tokenize)+ monkeypatch.setattr("rag.nlp.rag_tokenizer.fine_grained_tokenize", fake_tokenize)+++def test_empty_binary_does_not_open_display_name():+ email.chunk("message.eml", binary=b"", callback=lambda *a, **k: None)