Skip to content

Empty core-property date elements raise TypeError instead of returning None #1622

Description

@GreedyC

Description

Reading an empty core-property date element raises TypeError, while a missing element or an invalid date string returns None.

This affects created, modified, and last_printed when a document contains an empty corresponding XML element.

Reproduction

from docx.opc.coreprops import CoreProperties
from docx.oxml.parser import parse_xml

xml = b'''<cp:coreProperties
    xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
    xmlns:dcterms="http://purl.org/dc/terms/">
    <dcterms:created/>
</cp:coreProperties>'''

print(CoreProperties(parse_xml(xml)).created)

Expected: None, consistent with the existing handling of absent or invalid dates.

Actual: TypeError: 'NoneType' object is not subscriptable in _parse_W3CDTF_to_datetime.

Reproduced on current master with Python 3.12. Regression cases fail for all three empty date elements; whitespace and invalid-string controls already pass. I can submit a small guard with these tests.

I checked the existing fractional-seconds PR #1608; it changes date parsing but does not handle empty elements, so this is a separate case.

AI assistance was used to investigate and test this report.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions