Skip to content

Bug: _element_size fails for tables without API indices — blocks table insertion in new tabs/headers/footers/footnotes #54

@sripathikrishnan

Description

@sripathikrishnan

Parent Epic

#44

Bug

_element_size() in lower.py:2492 requires startIndex/endIndex to compute a table's character size. Synthetic content (new tab, new header, new footer, new footnote) has no API indices, so any path through _lower_content_insert with a table element raises NotImplementedError.

Root Cause

# lower.py:2492
def _element_size(el: StructuralElement) -> int:
    if el.paragraph is not None:
        return utf16_len(_para_text(el.paragraph))  # works
    if el.section_break is not None:
        return 1  # works
    start, end = _element_range(el)
    if start is not None and end is not None:
        return end - start
    raise NotImplementedError(...)  # tables hit this

For paragraphs, size is computed from text. For tables, it falls through to startIndex/endIndex which don't exist on synthetic content.

Affected Paths

All 5 content containers when creating a new segment:

  • addDocumentTab → body with table
  • createHeader → header with table
  • createFooter → footer with table
  • createFootnote → footnote with table
  • Any combination: paragraph → table → paragraph (running index breaks at table)

Suggested Fix

Compute table size from cell contents:

table_size = 1 (table opener) + sum_per_row(1 (row opener) + sum_per_cell(1 (cell opener) + cell_content_size))

Where cell_content_size recursively uses _element_size on cell content elements.

xfail Tests (7)

  • TestNewTabWithTable::test_new_tab_with_table
  • TestNewTabWithTable::test_new_tab_with_table_only
  • TestNewTabWithTable::test_new_tab_with_multi_paragraph_table_cell
  • TestElementSizeCascade::test_new_header_with_table_content
  • TestElementSizeCascade::test_new_footer_with_table_content
  • TestElementSizeCascade::test_new_footnote_with_table_content
  • TestElementSizeCascade::test_new_tab_para_table_para
  • TestNewHeaderMixedContent::test_new_header_text_then_table

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions