Skip to content

Skip non-image parts when gathering image parts - #1648

Open
draarivpatel-ui wants to merge 1 commit into
python-openxml:masterfrom
draarivpatel-ui:skip-non-image-parts
Open

draarivpatel-ui wants to merge 1 commit into
python-openxml:masterfrom
draarivpatel-ui:skip-non-image-parts

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Fixes #1565.

When a package is loaded, an image whose contents cannot be parsed (for example because of broken EXIF data) is represented by a plain Part object rather than an ImagePart. _gather_image_parts still adds it to the image-part collection, so a later add_picture() call fails while looking for duplicate images:

AttributeError: 'Part' object has no attribute 'sha1'

Skip relationship targets that are not ImagePart instances when gathering the image parts, mirroring the fix for the corresponding python-pptx issue (scanny/python-pptx#382). A package containing such a part can then still be extended with new pictures, and the already present (unparseable) image is left untouched.

An image whose contents cannot be parsed when a package is loaded
(e.g. because of broken EXIF data) is represented by a plain Part
object rather than an ImagePart. Because such parts have no .sha1
member, a later add_picture() call failed with:

    AttributeError: 'Part' object has no attribute 'sha1'

Skip relationship targets that are not ImagePart instances when
gathering image parts, mirroring the corresponding fix in python-pptx.

Fixes python-openxml#1565
Copilot AI balanced review requested due to automatic review settings November 25, 2026 23:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

Error when doing run add_picture: 'Part' object has no attribute 'sha1'

2 participants