From 68177a8702af20d2cb3aeb890d73f2951ee84c4f Mon Sep 17 00:00:00 2001 From: Tibor Tapai Date: Wed, 16 Apr 2025 18:53:28 +0200 Subject: [PATCH 1/2] fix(footnotes): check if footnote references are in document when accessing footnotes --- docx/parts/document.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docx/parts/document.py b/docx/parts/document.py index 652e88040..aa0290667 100644 --- a/docx/parts/document.py +++ b/docx/parts/document.py @@ -181,6 +181,13 @@ def _footnotes_part(self): part if one is not present. """ try: + # check if in document is used `footnoteReference`. + # If not then load the default footnote part. + # The footnote part xml remains after all the footnotes are deleted, + # so this check is to prevent loading of unused footnotes. + refs = self.document.element.xpath('//w:footnoteReference') + if len(refs) == 0: + raise KeyError return self.part_related_by(RT.FOOTNOTES) except KeyError: footnotes_part = FootnotesPart.default(self.package) From 18a326494318a1966a4eace981c5caf7a160ff7e Mon Sep 17 00:00:00 2001 From: Tibor Tapai Date: Wed, 16 Apr 2025 18:58:46 +0200 Subject: [PATCH 2/2] chore: bump version to v0.8.10.37 --- docx/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docx/__init__.py b/docx/__init__.py index d10141ef6..99d143440 100644 --- a/docx/__init__.py +++ b/docx/__init__.py @@ -2,7 +2,7 @@ from docx.api import Document # noqa -__version__ = '0.8.10.36' +__version__ = '0.8.10.37' # register custom Part classes with opc package reader