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 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)