Skip to content

fix(odf): attach comments in picture-only paragraphs to the picture - #4650

Open
devYRPauli wants to merge 3 commits into
docling-project:mainfrom
devYRPauli:fix/odf-comments-image-chart-paragraphs
Open

devYRPauli wants to merge 3 commits into
docling-project:mainfrom
devYRPauli:fix/odf-comments-image-chart-paragraphs

Conversation

@devYRPauli

@devYRPauli devYRPauli commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #4436.

_add_odf_paragraph returns early when a paragraph makes only pictures: an image with no other text, or a chart with only its replacement text. The return comes before comments.attach. The comment threads of that paragraph then reach attach_rest, and their groups land at the document root with no FineRef.

The fix:

  • _add_odf_images and _add_odf_charts return the PictureItem objects they add, not a count.
  • Before the early return, the paragraph attaches its threads to its first picture. Each thread becomes a COMMENT_SECTION group in the NOTES layer under the PictureItem, and the picture gets a FineRef in comments. This is the contract of the other items since fix(odf): keep ODT comments out of the body text #4436.
  • The backend adds the charts of a paragraph before its images. So in a paragraph with a chart and an image, the chart gets the threads.

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Review evidence:

Base 8aef0891 (main) and head 9a8b1475, on the ODT of the new test. The ODT has four paragraphs, and each paragraph has one comment.

paragraph main this branch
chart only group under #/body, no FineRef group under #/pictures/0, FineRef on the chart
two images group under #/body, no FineRef group under #/pictures/1 (the first image), FineRef on that image
chart and image group under #/body, no FineRef group under #/pictures/3 (the chart), FineRef on the chart
the text "See the chart." and a chart group under the text item, FineRef on the text item no change

Exports:

  • export_to_markdown(), export_to_html() and export_to_text() do not change. They exclude the NOTES layer.
  • export_to_doctags() includes all layers. On main it prints the 4 comments. On this branch it prints only the comment of the text paragraph. A markdown or HTML export with the NOTES layer changes in the same way.
  • The cause is iterate_items(). It skips the children of a PictureItem, except captions, unless traverse_pictures=True. With traverse_pictures=True in the serializer params, the markdown and DocTags serializers print all 4 comments, each right after its item.
  • The group stays under the PictureItem, as the review of fix(odf): keep ODT comments out of the body text #4436 asks. To keep the comments in exports with default parameters, the group can be a sibling after the picture instead. The FineRef on the picture stays the same.

Tests and checks:

  • test_odt_annotation_in_picture_paragraph_goes_to_picture builds the ODT in code from the chart and image frames of text_document_02.odt. So tests/data does not change. The test checks which pictures are charts and the parent and text of each comment group. It also checks the comments of each picture and of the text item.
  • With the backend of main, the new test fails:
    At index 0 diff: ('#/texts/0', '[author: Ann Reviewer]: Add a source.') != ('#/pictures/0', '[author: Ann Reviewer]: Label the axes.')
    
  • Eight mutants of the fix fail the new test:
    • no attach
    • the last picture: [*charts, *pictures][-1] and (charts or pictures)[-1]
    • the wrong first picture: (pictures or charts)[0] and (charts or pictures[::-1])[0]
    • an attach for charts only, and an attach for images only
    • the chart condition reduced to charts
  • tests/test_backend_opendocument.py: 52 passed on main, 53 passed on this branch. This includes the ground-truth test test_e2e_odf_conversions, with no reference-data change.
  • prek run --files on the two changed files, which is what make validate runs: all hooks pass, with no edits.
  • ty reports 39 warnings on opendocument_backend.py, on main and on this branch.
  • Not run locally: the other test files. test_cli.py and test_input_doc.py also use ODF files, but they only check format selection and do not convert.

Not covered: a comment in a paragraph inside a text box. That thread still goes to the document root, as on main. #4436 lists this case.

devYRPauli and others added 2 commits October 7, 2026 10:18
_add_odf_paragraph returned early for a paragraph that makes only an
image or a chart. The comment threads of that paragraph then reached
attach_rest and landed at the document root.

The paragraph now attaches its threads to its first picture: a
COMMENT_SECTION group in the NOTES layer, with a FineRef back-link.
_add_odf_images and _add_odf_charts return the pictures they add.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yash Raj Pandey <yashpn62@gmail.com>
The test now has a paragraph with two images, so it fails when the
threads go to the last picture. It also has a paragraph with text and
a chart. That paragraph keeps the comment on its text item.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yash Raj Pandey <yashpn62@gmail.com>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

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

@mergify

mergify Bot commented Oct 7, 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 Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/opendocument_backend.py 92.30% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working odf Issue related to the OpenDocument format (ODT, ODS, ODP) backend priority:low labels Nov 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 71e6a5cf4b. The analysis read the diff only. It did not run code from this pull request.

The PR fixes ODT comment placement for paragraphs that make only pictures. _add_odf_images and _add_odf_charts now return the PictureItem objects they add. _add_odf_paragraph attaches the comment threads to the first picture, or to the first chart, before it returns early.

Topic labels added: bug, odf, priority:low.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#4436 merged referenced as #4436 related: PR 4436 is merged. It added the _OdfComments mechanism and the comments.attach calls. This PR fixes one case that 4436 missed: the early return in _add_odf_paragraph for picture-only paragraphs. It does not repeat the change of 4436.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Nov 18, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the full diff at 71e6a5cf4b. It read the code and did not run it.

I found no defect. The change makes the early return in _add_odf_paragraph attach comment threads to the first picture. I checked the code paths and the regression test for it, and I did not run them.

A maintainer makes the merge decision. This review never approves the pull request.

This branch has not been deployed

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

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working odf Issue related to the OpenDocument format (ODT, ODS, ODP) backend priority:low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant