Skip to content

fix(layout): fix unreachable TABLE check in _handle_cross_type_overlaps#3701

Open
charlesaurav13 wants to merge 1 commit into
docling-project:mainfrom
charlesaurav13:fix/kvregion-table-dead-code
Open

fix(layout): fix unreachable TABLE check in _handle_cross_type_overlaps#3701
charlesaurav13 wants to merge 1 commit into
docling-project:mainfrom
charlesaurav13:fix/kvregion-table-dead-code

Conversation

@charlesaurav13

Copy link
Copy Markdown
Contributor

What

_handle_cross_type_overlaps has a dead code path for KEY_VALUE_REGION vs TABLE deduplication:

for regular in self.regular_clusters:
    if regular.label == DocItemLabel.TABLE:  # never True

TABLE is a member of WRAPPER_TYPES, which is a subset of SPECIAL_TYPES, so TABLE clusters always land in special_clusters and never in regular_clusters. This inner condition can never fire, so a KEY_VALUE_REGION that nearly coincides with a TABLE is never removed.

Fix

The tables list is already built from special_clusters in the PICTURE block added by #3523. This PR moves that list above both loops so it's shared, then iterates it in the wrapper loop instead of self.regular_clusters. A continue guard skips TABLE itself so it can't remove itself.

No change to the PICTURE/TABLE path from #3523.

Tests

Two new tests added to test_layout_postprocessor.py:

  • a KEY_VALUE_REGION coinciding with a TABLE is removed
  • a KEY_VALUE_REGION on a different part of the page is kept

Closes #3495

TABLE is a member of WRAPPER_TYPES, which is a subset of SPECIAL_TYPES,
so TABLE clusters always land in special_clusters and never in
regular_clusters. The inner condition

    for regular in self.regular_clusters:
        if regular.label == DocItemLabel.TABLE:

could therefore never be true, making the KEY_VALUE_REGION vs TABLE
deduplication path a complete no-op.

Fix by building the tables list from special_clusters (already done
below for the PICTURE case added in docling-project#3523) and moving it above both
loops so it is shared. Add an explicit skip for TABLE itself so a
TABLE cluster cannot trigger its own removal.

Adds two unit tests: one that confirms a near-identical KEY_VALUE_REGION
is dropped, and one that confirms a non-overlapping one is kept.

Fixes docling-project#3495

Signed-off-by: Saurav Pandey <sauravp1236@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @charlesaurav13, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: borderless table detected as both TableItem and PictureItem (dead code in _handle_cross_type_overlaps)

1 participant