Repository navigation
Conversation
DOCXToDocument read a table cell through cell.paragraphs, which holds only the cell's direct paragraphs, so a table nested in the cell was dropped. The cell is now read with iter_inner_content(), and a nested table is written in place, one line per row with its cells separated by " | ". Merged cells of the nested table are read once. Fixes deepset-ai#13905
|
@hass44 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
Ran this at b0b5f44 against main (45949b5). With python-docx 1.2.0 the fix works: a 1x2 table with a 1x2 table nested in the second cell goes from One problem: That includes a plain 1x2 table with no nesting (main returns Two ways out: add for child in cell._tc.iterchildren():
if child.tag.endswith("}p"):
lines.append(self._process_links_in_paragraph(Paragraph(child, cell)))
elif child.tag.endswith("}tbl"):
lines.extend(self._nested_table_lines(Table(child, cell)))With that swapped in, all 5 new tests pass on both 1.0.1 and 1.2.0, and 1.0.1 is back to main's 5 unrelated failures. Smaller note, not a regression: a nested table wrapped in a block content control ( |
Related Issues
Proposed Changes:
DOCXToDocumentread each table cell throughcell.paragraphs, which holds only the cell's direct paragraphs, so a table nested in a cell was dropped without a warning. Nested tables are common in Word forms, invoices and CV templates, where the dropped part is often the content people search for (contact details, line items)._cell_textnow walks the cell withcell.iter_inner_content(). A nested table is written in place, one line per row, with its cells separated by|. It works at any depth, links inside it followlink_format, and a merged cell of the nested table is read once instead of once per row or column it spans.With a 2x2 table nested in the second cell (
table_format="csv"), the output changes fromouter,to:How did you test it?
test_docx_file_to_document.py: nested table in both table formats, two levels deep, merged cells in the nested table, a link in a nested cell. All 5 fail onmainand pass with the change. The whole module passes (56 tests).ruff check,ruff format --checkandmypyon the changed files are clean.Notes for the reviewer
#13906 fixed the same issue but was closed because its CLA was never signed. This PR also keeps the nested rows on one line each and reads merged cells once.
Checklist
fix:.