Skip to content

Fix inline image reuse after merging image-bearing subdoc - #666

Open
ahmetmusab42-stack wants to merge 1 commit into
elapouya:masterfrom
ahmetmusab42-stack:fix-issue-474
Open

Fix inline image reuse after merging image-bearing subdoc#666
ahmetmusab42-stack wants to merge 1 commit into
elapouya:masterfrom
ahmetmusab42-stack:fix-issue-474

Conversation

@ahmetmusab42-stack

@ahmetmusab42-stack ahmetmusab42-stack commented Sep 1, 2026

Copy link
Copy Markdown

Summary

  • normalize only the matching copied-image wrapper when an InlineImage reuses an image already introduced by docxcompose;
  • preserve the existing fast path and unrelated image/error behavior;
  • add regression coverage for path and BytesIO descriptors, repeated rendering, image deduplication, and an unsupported-image subdocument.

Root cause

When a subdocument contributes an image, docxcompose can cache that image part with its lightweight ImageWrapper. If a later InlineImage has the same bytes, python-docx reuses the part and expects the returned image object to implement scaled_dimensions(). The wrapper does not, so rendering raises AttributeError.

The fix replaces only the checksum-matching wrapper with a native python-docx Image before the normal new_pic_inline() path runs. It does not monkey-patch third-party classes or catch broad exceptions.

Verification

  • reproduced can not insert a inline image and a subdoc with an image #474 on current master with the reporter's template1.docx, template2.docx, and index.jpeg;
  • verified those exact fixtures render with this change;
  • new regression script passed on Python 3.9, 3.10, 3.13, and 3.14 with python-docx 1.2.0 / docxcompose 2.2.0;
  • legacy combination passed with python-docx 1.1.2 / docxcompose 1.4.1;
  • 37 existing direct test scripts passed;
  • Flake8, git diff --check, sdist, and wheel builds passed.

Fixes #474.

OpenAI Codex assisted with reproduction, implementation, and test execution. I reviewed the diff and verification results and remain responsible for this contribution.

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.

can not insert a inline image and a subdoc with an image

1 participant