Skip to content

Commit

Permalink
fix: skip comment blocks in DOCXToDocument (#8764)
Browse files Browse the repository at this point in the history
* fix bug #8759

* Apply suggestions from code review

* release note

---------

Co-authored-by: Stefano Fiorucci <[email protected]>
  • Loading branch information
Night-Quiet and anakin87 authored Jan 24, 2025
1 parent 223373e commit c989d9c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions haystack/components/converters/docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from docx.document import Document as DocxDocument
from docx.table import Table
from docx.text.paragraph import Paragraph
from lxml.etree import _Comment


@dataclass
Expand Down Expand Up @@ -210,6 +211,8 @@ def _extract_elements(self, document: "DocxDocument") -> List[str]:
"""
elements = []
for element in document.element.body:
if isinstance(element, _Comment):
continue
if element.tag.endswith("p"):
paragraph = Paragraph(element, document)
if paragraph.contains_page_break:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
The DOCXToDocument component now skips comment blocks in DOCX files that previously caused errors.

0 comments on commit c989d9c

Please sign in to comment.