diff --git a/src/docx/opc/constants.py b/src/docx/opc/constants.py index 89d3c16cc..c304cf3d7 100644 --- a/src/docx/opc/constants.py +++ b/src/docx/opc/constants.py @@ -313,6 +313,10 @@ class RELATIONSHIP_TYPE: "http://schemas.openxmlformats.org/package/2006/relationships/metada" "ta/core-properties" ) + CORE_PROPERTIES_OFFICEDOCUMENT = ( + "http://schemas.openxmlformats.org/officedocument/2006/relationships" + "/metadata/core-properties" + ) CUSTOM_PROPERTIES = ( "http://schemas.openxmlformats.org/officeDocument/2006/relationships" "/custom-properties" diff --git a/src/docx/opc/package.py b/src/docx/opc/package.py index 3b1eef256..29c8eb05f 100644 --- a/src/docx/opc/package.py +++ b/src/docx/opc/package.py @@ -175,9 +175,15 @@ def _core_properties_part(self) -> CorePropertiesPart: try: return cast(CorePropertiesPart, self.part_related_by(RT.CORE_PROPERTIES)) except KeyError: - core_properties_part = CorePropertiesPart.default(self) - self.relate_to(core_properties_part, RT.CORE_PROPERTIES) - return core_properties_part + try: + office_document_part = self.part_related_by(RT.CORE_PROPERTIES_OFFICEDOCUMENT) + rel = self.relate_to(office_document_part, RT.CORE_PROPERTIES_OFFICEDOCUMENT) + self.rels[rel].set_reltype(RT.CORE_PROPERTIES) + return cast(CorePropertiesPart, office_document_part) + except KeyError: + core_properties_part = CorePropertiesPart.default(self) + self.relate_to(core_properties_part, RT.CORE_PROPERTIES) + return core_properties_part class Unmarshaller: diff --git a/src/docx/opc/rel.py b/src/docx/opc/rel.py index 47e8860d8..cd5176d68 100644 --- a/src/docx/opc/rel.py +++ b/src/docx/opc/rel.py @@ -134,6 +134,9 @@ def is_external(self) -> bool: def reltype(self) -> str: return self._reltype + def set_reltype(self, reltype:str) -> None: + self._reltype = reltype + @property def rId(self) -> str: return self._rId