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


##########
pyproject.toml:
##########
@@ -61,6 +61,7 @@ version = "3.3.0"
 dependencies = [
     "apache-airflow-task-sdk<1.4.0,>=1.3.0",
     "apache-airflow-core==3.3.0",
+    "isoduration>=20.11.0",

Review Comment:
   Should this belong to the distributions that actually import it  
(`task-sdk/pyproject.toml`  and `airflow-core/pyproject.toml`?



##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDuration.tsx:
##########
@@ -0,0 +1,72 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { Input } from "@chakra-ui/react";
+import { parse } from "iso8601-duration";
+import { useTranslation } from "react-i18next";
+
+import { paramPlaceholder, useParamStore } from "src/queries/useParamStore";
+
+import type { FlexibleFormElementProps } from ".";
+
+export const FieldDuration = ({ name, namespace = "default", onUpdate }: 
FlexibleFormElementProps) => {
+  const { t: translate } = useTranslation("components");
+  const { disabled, paramsDict, setParamsDict } = useParamStore(namespace);
+  const param = paramsDict[name] ?? paramPlaceholder;
+
+  const handleChange = (value: string) => {
+    const isEmpty = value === "";
+    const normalize = value.replaceAll(",", ".");

Review Comment:
   The backend test matrix includes `PT1,5H`, but this normalizes commas before 
storing, so that case is unreachable from the UI. Drop the case on the backend 
or stop normalizing here.



##########
task-sdk/tests/task_sdk/definitions/test_param.py:
##########
@@ -138,6 +138,40 @@ def test_string_date_format_error(self, date_string):
         with pytest.raises(ParamValidationError, match="is not a 'date'"):
             Param(date_string, type="string", format="date").resolve()
 
+    @pytest.mark.parametrize(

Review Comment:
   I see tests here but not in the `airflow-core` path.



##########
task-sdk/src/airflow/sdk/definitions/param.py:
##########
@@ -34,6 +37,25 @@
 
 logger = logging.getLogger(__name__)
 
+# 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).
+
+
+def get_format_duration() -> FormatChecker:

Review Comment:
   question: do we actually need this helper? My reading of the [jsonschema 
docs](https://python-jsonschema.readthedocs.io/en/stable/validate/#validating-formats)
 is that as soon as `isoduration` is importable `jsonschema` auto-registers a 
duration checker on the default `FormatChecker`. If that's right, once the dep 
is declared on the right distribution we shouldn't need to swap 
`format_checker=FormatChecker()` at all, the existing call already validates 
`format="duration"` for free.



##########
airflow-core/src/airflow/serialization/definitions/param.py:
##########
@@ -22,12 +22,32 @@
 import copy
 from typing import TYPE_CHECKING, Any, Literal
 
+from isoduration import parse_duration
+from jsonschema import FormatChecker
+
 from airflow.serialization.definitions.notset import NOTSET, is_arg_set
 
 if TYPE_CHECKING:
     from collections.abc import Iterator, Mapping
 
 
+def get_format_duration() -> FormatChecker:

Review Comment:
   same as in `airflow-task-sdk`:
   
   question: do we actually need this helper? My reading of the [jsonschema 
docs](https://python-jsonschema.readthedocs.io/en/stable/validate/#validating-formats)
 is that as soon as `isoduration` is importable `jsonschema` auto-registers a 
duration checker on the default `FormatChecker`. If that's right, once the dep 
is declared on the right distribution we shouldn't need to swap 
`format_checker=FormatChecker()` at all, the existing call already validates 
`format="duration"` for free.



-- 
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