jjCode01 / xerparser

Parse the contents of a P6 .xer file into a Python object
GNU General Public License v3.0
20 stars 5 forks source link

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

Closed sayer122 closed 2 months ago

sayer122 commented 2 months ago

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"])
jjCode01 commented 2 months ago

I've used your fixes on this one as well, there is no reason they can't be optional dates. Just curious, what version are the xer files?

sayer122 commented 1 month ago

Thank you so much! I believe I hit this using versions between 8.1 - 8.3

sayer122 commented 1 month ago

Thank you so much! I believe I hit this using versions between 8.1 - 8.3