Describe the bug
When declaring an attribute or slot with a range of datetime, a ValueError: Invalid isoformat string error is raised in Python when running version prior to 3.11
Suggestion
In metaamodelcore.py, automatically replace a trailing Z with +00:00 if Python version is < 3.11 (or always)
To reproduce
in Python < 3.11
from datetime import datetime
datetime.fromisoformat("2024-03-20T19:26:08.00Z") # fails
datetime.fromisoformat("2024-03-20T19:26:08.00+00:00") # works
datetime.fromisoformat("2024-03-20T19:26:08.00") # works, but no timezone
In LinkML
(1) Define a slot or attribute with range datetime, such as
created_date:
description: The date the service was created
range: datetime
(2) Parse from a JSON containing with an ISO date with a traillng Z, such as
2024-03-20T19:26:08.000000Z
Expected behavior
No error when parsing the ISO string
Describe the bug When declaring an attribute or slot with a range of
datetime
, aValueError: Invalid isoformat string
error is raised in Python when running version prior to 3.11See https://note.nkmk.me/en/python-datetime-isoformat-fromisoformat/#isoformat-string-with-z
Workaround Replace
Z
with+00:00
(or use Python >= 3.11)See https://github.com/nkmk/python-snippets/blob/028c2bcd15e7c776c445ed39e6513801450ed2dc/notebook/datetime_isoformat_timezone.py#L30-L36
Suggestion In metaamodelcore.py, automatically replace a trailing Z with +00:00 if Python version is < 3.11 (or always)
To reproduce
in Python < 3.11
In LinkML (1) Define a slot or attribute with range
datetime
, such as(2) Parse from a JSON containing with an ISO date with a traillng Z, such as
2024-03-20T19:26:08.000000Z
Expected behavior No error when parsing the ISO string