Skip to content

Commit 1752b7e

Browse files
committed
feat: improve XSD-date validation
XSD-date cannot be written in the form "CCYYMMDD", this patch adds a test to ensure it. linkml-runtime has been relying on Python `fromisoformat` [1] format to parse and, implicitly validate, XSD-date. But from Python 3.11 upwards `fromisoformat` also accepts "CCYYMMDD" as a valid date, breaking XSD-date compatibility. Signed-off-by: Silvano Cirujano Cuesta <silvano.cirujano-cuesta@siemens.com>
1 parent 4c3ba9f commit 1752b7e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

linkml_runtime/utils/metamodelcore.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ def is_valid(cls, value: Union[str, datetime.date, Literal]) -> bool:
278278
value = value.value
279279
if isinstance(value, datetime.date):
280280
value = value.isoformat()
281+
if not re.match(r'^\d{4}-\d{2}-\d{2}$', value):
282+
return False
281283
try:
282284
datetime.date.fromisoformat(str(value))
283285
except ValueError:

0 commit comments

Comments
 (0)