aeroyorch commented on code in PR #65469:
URL: https://github.com/apache/airflow/pull/65469#discussion_r3120693347


##########
airflow-core/src/airflow/serialization/definitions/param.py:
##########
@@ -20,13 +20,44 @@
 
 import collections.abc
 import copy
+import re
 from typing import TYPE_CHECKING, Any, Literal
 
 from airflow.serialization.definitions.notset import NOTSET, is_arg_set
 
 if TYPE_CHECKING:
     from collections.abc import Iterator, Mapping
 
+# Matches ISO 8601 duration strings such as PT15M, P1Y2M3DT4H5M6S, P1W, 
P1DT30S.
+# Decimal fractions with either "." or "," are allowed on any component (e.g. 
PT1.5H, PT30.5S).
+_ISO8601_DURATION_RE = re.compile(
+    r"^P"
+    r"(?:\d+(?:[.,]\d+)?Y)?"
+    r"(?:\d+(?:[.,]\d+)?M)?"
+    r"(?:\d+(?:[.,]\d+)?W)?"
+    r"(?:\d+(?:[.,]\d+)?D)?"
+    r"(?:T(?:\d+(?:[.,]\d+)?H)?(?:\d+(?:[.,]\d+)?M)?(?:\d+(?:[.,]\d+)?S)?)?"
+    r"$"
+)
+
+
+def _check_iso8601_duration(instance: str) -> bool:
+    """Validate an ISO 8601 duration string. Used as a jsonschema format 
checker."""
+    if not isinstance(instance, str):
+        return True
+    if not _ISO8601_DURATION_RE.fullmatch(instance) or instance in ("P", "PT"):
+        raise ValueError(f"{instance!r} is not a valid ISO 8601 duration")
+    return True
+
+
+def _make_format_checker() -> Any:

Review Comment:
   Not sure if this is needed. I think `jsonschema` may already support 
duration format checking, although it [requires the optional `isoduration` 
dependency](https://python-jsonschema.readthedocs.io/en/stable/validate/#validating-formats).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to