Skip to content

Error when loading xer file with missing task create_date or update_date  #8

@sayer122

Description

@sayer122

I've hit another issue when reading a file that has a missing create_date in the tasks table. Is there any reason that these can't be optional_dates?

    xer = Xer.reader(xer_filepath)
          ^^^^^^^^^^^^^^^^^^^^^^^^
...

lib/python3.12/site-packages/xerparser/schemas/task.py", line 173, in __init__
    self.create_date: datetime = datetime.strptime(data["create_date"], date_format)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/_strptime.py", line 554, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/_strptime.py", line 333, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '' does not match format '%Y-%m-%d %H:%M'

I'm able to get around this by updating:

        self.create_date: datetime = datetime.strptime(data["create_date"], date_format)
        self.update_date: datetime = datetime.strptime(data["update_date"], date_format)

To use the optional_date validator

        self.create_date: datetime | None = optional_date(data["create_date"])
        self.update_date: datetime | None = optional_date(data["update_date"])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions