Skip to content

Commit 76edf74

Browse files
author
王屹
committed
fix: python-openxml#1565 skip sha1 check for broken image_part on .add_picture()
Run.add_picture() raises 'Part' object has no attribute 'sha1'
1 parent e454546 commit 76edf74

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎src/docx/package.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def _get_by_sha1(self, sha1: str) -> ImagePart | None:
8888
"""Return the image part in this collection having a SHA1 hash matching `sha1`,
8989
or |None| if not found."""
9090
for image_part in self._image_parts:
91+
if not hasattr(image_part, 'sha1'):
92+
continue
9193
if image_part.sha1 == sha1:
9294
return image_part
9395
return None

0 commit comments

Comments
 (0)