You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Lee-W (via GitHub)" <gi...@apache.org> on 2025/08/22 11:06:46 UTC

[PR] feat(hitl): add utility function generate_link_to_ui [airflow]

Lee-W opened a new pull request, #54827:
URL: https://github.com/apache/airflow/pull/54827

   <!--
    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.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(hitl): add utility functions for generating the url to required actions page [airflow]

Posted by "jscheffl (via GitHub)" <gi...@apache.org>.
jscheffl commented on PR #54827:
URL: https://github.com/apache/airflow/pull/54827#issuecomment-3225414098

   > Hey @jscheffl , I just rewrote the function with an example and doc update. Would be nice if you can take another look thanks!
   
   Cool! Thanks!


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(hitl): add utility functions for generating the url to required actions page [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W merged PR #54827:
URL: https://github.com/apache/airflow/pull/54827


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(hitl): add utility function generate_link_to_ui [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on PR #54827:
URL: https://github.com/apache/airflow/pull/54827#issuecomment-3220560325

   cc @guan404ming 


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(hitl): add utility functions for generating the url to required actions page [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #54827:
URL: https://github.com/apache/airflow/pull/54827#discussion_r2303243975


##########
providers/standard/src/airflow/providers/standard/operators/hitl.py:
##########
@@ -87,12 +89,33 @@ def __init__(
         self.respondents = [respondents] if isinstance(respondents, str) else respondents
 
         self.validate_options()
+        self.validate_params()
         self.validate_defaults()
 
     def validate_options(self) -> None:
+        """
+        Validate the `options` attribute of the instance.
+
+        Raises:
+            ValueError: If `options` is empty.
+            ValueError: If any option contains a comma (`,`), which is not allowed.
+        """
         if not self.options:
             raise ValueError('"options" cannot be empty.')
 
+        if any("," in option for option in self.options):
+            raise ValueError('"," is not allowed in option')
+
+    def validate_params(self) -> None:

Review Comment:
   Not really. it's part of the `__init__`. `__init__` raises error if `validte_parms` does not pass



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(hitl): add utility functions for generating the url to required actions page [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #54827:
URL: https://github.com/apache/airflow/pull/54827#discussion_r2303244889


##########
providers/standard/src/airflow/providers/standard/operators/hitl.py:
##########
@@ -87,12 +89,33 @@ def __init__(
         self.respondents = [respondents] if isinstance(respondents, str) else respondents
 
         self.validate_options()
+        self.validate_params()
         self.validate_defaults()
 
     def validate_options(self) -> None:
+        """
+        Validate the `options` attribute of the instance.
+
+        Raises:
+            ValueError: If `options` is empty.
+            ValueError: If any option contains a comma (`,`), which is not allowed.
+        """
         if not self.options:
             raise ValueError('"options" cannot be empty.')
 
+        if any("," in option for option in self.options):

Review Comment:
   Not really. it's part of the `__init__`. `__init__` raises error if `validate_options` does not pass. but I add a comment in the test cases.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(hitl): add utility functions for generating the url to required actions page [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on PR #54827:
URL: https://github.com/apache/airflow/pull/54827#issuecomment-3227315889

   I'm going to merge this one as the functionality is ready and it improves the doc. I will create a separate PR if the detail is changed in https://github.com/apache/airflow/pull/54783


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(hitl): add utility function generate_link_to_ui [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on PR #54827:
URL: https://github.com/apache/airflow/pull/54827#issuecomment-3222357684

   > Cool! That is a good helper!
   > 
   > Can you also in #54783 (or here?) reference this in some kind of documentation such that users can find this helper?
   
   yep, this will be added to the HITL tutorial page. I thought of making that a separate PR, but after a second thought, I could probably just update this one. 


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(hitl): add utility functions for generating the url to required actions page [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #54827:
URL: https://github.com/apache/airflow/pull/54827#discussion_r2300787789


##########
providers/standard/src/airflow/providers/standard/operators/hitl.py:
##########
@@ -87,12 +89,33 @@ def __init__(
         self.respondents = [respondents] if isinstance(respondents, str) else respondents
 
         self.validate_options()
+        self.validate_params()
         self.validate_defaults()
 
     def validate_options(self) -> None:
+        """
+        Validate the `options` attribute of the instance.
+
+        Raises:
+            ValueError: If `options` is empty.
+            ValueError: If any option contains a comma (`,`), which is not allowed.
+        """
         if not self.options:
             raise ValueError('"options" cannot be empty.')
 
+        if any("," in option for option in self.options):

Review Comment:
   The unit test for `validate_options` needs update:
   https://github.com/apache/airflow/blob/26515d3ef28212b5164779205cdf1f6495665f32/providers/standard/tests/unit/standard/operators/test_hitl.py#L58



##########
providers/standard/src/airflow/providers/standard/operators/hitl.py:
##########
@@ -87,12 +89,33 @@ def __init__(
         self.respondents = [respondents] if isinstance(respondents, str) else respondents
 
         self.validate_options()
+        self.validate_params()
         self.validate_defaults()
 
     def validate_options(self) -> None:
+        """
+        Validate the `options` attribute of the instance.
+
+        Raises:
+            ValueError: If `options` is empty.
+            ValueError: If any option contains a comma (`,`), which is not allowed.
+        """
         if not self.options:
             raise ValueError('"options" cannot be empty.')
 
+        if any("," in option for option in self.options):
+            raise ValueError('"," is not allowed in option')
+
+    def validate_params(self) -> None:

Review Comment:
   The unit test for `validate_params` is missing.



##########
providers/standard/tests/unit/standard/operators/test_hitl.py:
##########
@@ -238,6 +264,170 @@ def test_validate_params_input_with_invalid_input(self) -> None:
                 },
             )
 
+    @pytest.mark.parametrize(
+        "options, params_input, expected_query_string",
+        [
+            (None, None, "?map_index=-1"),
+            ("1", None, "?_options=1&map_index=-1"),
+            (["1", "2"], None, "?_options=1%2C2&map_index=-1"),
+            (None, {"input_1": 123}, "?input_1=123&map_index=-1"),
+            (
+                ["3", "4", "5"],
+                {"input_1": 123123, "input_2": 345345},
+                "?_options=3%2C4%2C5&input_1=123123&input_2=345345&map_index=-1",
+            ),
+        ],
+        ids=[
+            "empty",
+            "single-option",
+            "multiple-options",
+            "single-param-input",
+            "multiple-options-and-param-inputs",
+        ],
+    )
+    @pytest.mark.parametrize("base_url", ["http://test", "http://test_2:8080"])
+    def test_generate_link_to_ui(
+        self,
+        dag_maker: DagMaker,
+        base_url: str,
+        options: list[str] | None,
+        params_input: dict[str, Any] | None,
+        expected_query_string: str,
+    ) -> None:
+        with dag_maker("test_dag"):
+            task = HITLOperator(
+                task_id="hitl_test",
+                subject="This is subject",
+                options=["1", "2", "3", "4", "5"],
+                body="This is body",
+                defaults=["1"],
+                respondents="test",
+                multiple=True,
+                params=ParamsDict({"input_1": 1, "input_2": 2, "input_3": 3}),
+            )
+        dr = dag_maker.create_dagrun()
+        ti = dag_maker.run_ti(task.task_id, dr)
+
+        expected_url = (
+            f"{base_url}/dags/test_dag/runs/test/tasks/hitl_test/required_actions{expected_query_string}"
+        )
+
+        url = task.generate_link_to_ui(
+            task_instance=ti,
+            base_url=base_url,
+            options=options,
+            params_input=params_input,
+        )
+        assert url == expected_url
+
+    @pytest.mark.parametrize(
+        "options, params_input, expected_query_string",
+        [
+            (None, None, "?map_index=-1"),
+            ("1", None, "?_options=1&map_index=-1"),
+            (["1", "2"], None, "?_options=1%2C2&map_index=-1"),
+            (None, {"input_1": 123}, "?input_1=123&map_index=-1"),
+            (
+                ["3", "4", "5"],
+                {"input_1": 123123, "input_2": 345345},
+                "?_options=3%2C4%2C5&input_1=123123&input_2=345345&map_index=-1",
+            ),
+        ],
+        ids=[
+            "empty",
+            "single-option",
+            "multiple-options",
+            "single-param-input",
+            "multiple-options-and-param-inputs",
+        ],
+    )
+    @conf_vars({("api", "base_url"): "http://localhost:8080/"})
+    def test_generate_link_fall_back_to_conf_api_base_url(
+        self,
+        dag_maker: DagMaker,
+        options: list[str] | None,
+        params_input: dict[str, Any] | None,
+        expected_query_string: str,
+    ) -> None:
+        with dag_maker("test_dag"):
+            task = HITLOperator(
+                task_id="hitl_test",
+                subject="This is subject",
+                options=["1", "2", "3", "4", "5"],
+                body="This is body",
+                defaults=["1"],
+                respondents="test",
+                multiple=True,
+                params=ParamsDict({"input_1": 1, "input_2": 2, "input_3": 3}),
+            )
+        dr = dag_maker.create_dagrun()
+        ti = dag_maker.run_ti(task.task_id, dr)
+
+        expected_url = f"http://localhost:8080/dags/test_dag/runs/test/tasks/hitl_test/required_actions{expected_query_string}"
+
+        url = task.generate_link_to_ui(
+            task_instance=ti,
+            options=options,
+            params_input=params_input,
+        )
+        assert url == expected_url
+
+    @pytest.mark.parametrize(
+        "options, params_input, expected_err_msg",
+        [
+            ([100, "2", 30000], None, "options {.*} are not valid options"),
+            (
+                None,
+                {"input_not_exist": 123, "no_such_key": 123},
+                "params {.*} are not valid params",
+            ),
+        ],
+    )
+    def test_generate_link_to_ui_with_invalid_input(
+        self,
+        dag_maker: DagMaker,
+        options: list[str] | None,
+        params_input: dict[str, Any] | None,
+        expected_err_msg: str,
+    ) -> None:
+        with dag_maker("test_dag"):
+            task = HITLOperator(
+                task_id="hitl_test",
+                subject="This is subject",
+                options=["1", "2", "3", "4", "5"],
+                body="This is body",
+                defaults=["1"],
+                respondents="test",
+                multiple=True,
+                params=ParamsDict({"input_1": 1, "input_2": 2, "input_3": 3}),
+            )
+        dr = dag_maker.create_dagrun()
+        ti = dag_maker.run_ti(task.task_id, dr)
+
+        with pytest.raises(ValueError, match=expected_err_msg):
+            task.generate_link_to_ui(task_instance=ti, options=options, params_input=params_input)
+
+    def test_generate_link_to_ui_without_base_url(
+        self,
+        dag_maker: DagMaker,
+    ) -> None:
+        with dag_maker("test_dag"):
+            task = HITLOperator(
+                task_id="hitl_test",
+                subject="This is subject",
+                options=["1", "2", "3", "4", "5"],
+                body="This is body",
+                defaults=["1"],
+                respondents="test",
+                multiple=True,
+                params=ParamsDict({"input_1": 1, "input_2": 2, "input_3": 3}),
+            )
+        dr = dag_maker.create_dagrun()
+        ti = dag_maker.run_ti(task.task_id, dr)

Review Comment:
   How about having another fixture to setup the Dag for generating link for UI and yield the `HITLOperator  instance`, `DagRun` and `TaskInstance`?
   It seems the Dags added in this PR are same.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(hitl): add utility functions for generating the url to required actions page [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #54827:
URL: https://github.com/apache/airflow/pull/54827#discussion_r2303242379


##########
providers/standard/tests/unit/standard/operators/test_hitl.py:
##########
@@ -238,6 +264,170 @@ def test_validate_params_input_with_invalid_input(self) -> None:
                 },
             )
 
+    @pytest.mark.parametrize(
+        "options, params_input, expected_query_string",
+        [
+            (None, None, "?map_index=-1"),
+            ("1", None, "?_options=1&map_index=-1"),
+            (["1", "2"], None, "?_options=1%2C2&map_index=-1"),
+            (None, {"input_1": 123}, "?input_1=123&map_index=-1"),
+            (
+                ["3", "4", "5"],
+                {"input_1": 123123, "input_2": 345345},
+                "?_options=3%2C4%2C5&input_1=123123&input_2=345345&map_index=-1",
+            ),
+        ],
+        ids=[
+            "empty",
+            "single-option",
+            "multiple-options",
+            "single-param-input",
+            "multiple-options-and-param-inputs",
+        ],
+    )
+    @pytest.mark.parametrize("base_url", ["http://test", "http://test_2:8080"])
+    def test_generate_link_to_ui(
+        self,
+        dag_maker: DagMaker,
+        base_url: str,
+        options: list[str] | None,
+        params_input: dict[str, Any] | None,
+        expected_query_string: str,
+    ) -> None:
+        with dag_maker("test_dag"):
+            task = HITLOperator(
+                task_id="hitl_test",
+                subject="This is subject",
+                options=["1", "2", "3", "4", "5"],
+                body="This is body",
+                defaults=["1"],
+                respondents="test",
+                multiple=True,
+                params=ParamsDict({"input_1": 1, "input_2": 2, "input_3": 3}),
+            )
+        dr = dag_maker.create_dagrun()
+        ti = dag_maker.run_ti(task.task_id, dr)
+
+        expected_url = (
+            f"{base_url}/dags/test_dag/runs/test/tasks/hitl_test/required_actions{expected_query_string}"
+        )
+
+        url = task.generate_link_to_ui(
+            task_instance=ti,
+            base_url=base_url,
+            options=options,
+            params_input=params_input,
+        )
+        assert url == expected_url
+
+    @pytest.mark.parametrize(
+        "options, params_input, expected_query_string",
+        [
+            (None, None, "?map_index=-1"),
+            ("1", None, "?_options=1&map_index=-1"),
+            (["1", "2"], None, "?_options=1%2C2&map_index=-1"),
+            (None, {"input_1": 123}, "?input_1=123&map_index=-1"),
+            (
+                ["3", "4", "5"],
+                {"input_1": 123123, "input_2": 345345},
+                "?_options=3%2C4%2C5&input_1=123123&input_2=345345&map_index=-1",
+            ),
+        ],
+        ids=[
+            "empty",
+            "single-option",
+            "multiple-options",
+            "single-param-input",
+            "multiple-options-and-param-inputs",
+        ],
+    )
+    @conf_vars({("api", "base_url"): "http://localhost:8080/"})
+    def test_generate_link_fall_back_to_conf_api_base_url(
+        self,
+        dag_maker: DagMaker,
+        options: list[str] | None,
+        params_input: dict[str, Any] | None,
+        expected_query_string: str,
+    ) -> None:
+        with dag_maker("test_dag"):
+            task = HITLOperator(
+                task_id="hitl_test",
+                subject="This is subject",
+                options=["1", "2", "3", "4", "5"],
+                body="This is body",
+                defaults=["1"],
+                respondents="test",
+                multiple=True,
+                params=ParamsDict({"input_1": 1, "input_2": 2, "input_3": 3}),
+            )
+        dr = dag_maker.create_dagrun()
+        ti = dag_maker.run_ti(task.task_id, dr)
+
+        expected_url = f"http://localhost:8080/dags/test_dag/runs/test/tasks/hitl_test/required_actions{expected_query_string}"
+
+        url = task.generate_link_to_ui(
+            task_instance=ti,
+            options=options,
+            params_input=params_input,
+        )
+        assert url == expected_url
+
+    @pytest.mark.parametrize(
+        "options, params_input, expected_err_msg",
+        [
+            ([100, "2", 30000], None, "options {.*} are not valid options"),
+            (
+                None,
+                {"input_not_exist": 123, "no_such_key": 123},
+                "params {.*} are not valid params",
+            ),
+        ],
+    )
+    def test_generate_link_to_ui_with_invalid_input(
+        self,
+        dag_maker: DagMaker,
+        options: list[str] | None,
+        params_input: dict[str, Any] | None,
+        expected_err_msg: str,
+    ) -> None:
+        with dag_maker("test_dag"):
+            task = HITLOperator(
+                task_id="hitl_test",
+                subject="This is subject",
+                options=["1", "2", "3", "4", "5"],
+                body="This is body",
+                defaults=["1"],
+                respondents="test",
+                multiple=True,
+                params=ParamsDict({"input_1": 1, "input_2": 2, "input_3": 3}),
+            )
+        dr = dag_maker.create_dagrun()
+        ti = dag_maker.run_ti(task.task_id, dr)
+
+        with pytest.raises(ValueError, match=expected_err_msg):
+            task.generate_link_to_ui(task_instance=ti, options=options, params_input=params_input)
+
+    def test_generate_link_to_ui_without_base_url(
+        self,
+        dag_maker: DagMaker,
+    ) -> None:
+        with dag_maker("test_dag"):
+            task = HITLOperator(
+                task_id="hitl_test",
+                subject="This is subject",
+                options=["1", "2", "3", "4", "5"],
+                body="This is body",
+                defaults=["1"],
+                respondents="test",
+                multiple=True,
+                params=ParamsDict({"input_1": 1, "input_2": 2, "input_3": 3}),
+            )
+        dr = dag_maker.create_dagrun()
+        ti = dag_maker.run_ti(task.task_id, dr)

Review Comment:
   I later make it `hitl_task_and_ti_for_generating_link`. Not a fan of making the return type complicate, but I guess that's the best we can do now 🤔 



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(hitl): add utility functions for generating the url to required actions page [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #54827:
URL: https://github.com/apache/airflow/pull/54827#discussion_r2300782156


##########
providers/standard/tests/unit/standard/operators/test_hitl.py:
##########
@@ -238,6 +264,170 @@ def test_validate_params_input_with_invalid_input(self) -> None:
                 },
             )
 
+    @pytest.mark.parametrize(
+        "options, params_input, expected_query_string",
+        [
+            (None, None, "?map_index=-1"),
+            ("1", None, "?_options=1&map_index=-1"),
+            (["1", "2"], None, "?_options=1%2C2&map_index=-1"),
+            (None, {"input_1": 123}, "?input_1=123&map_index=-1"),
+            (
+                ["3", "4", "5"],
+                {"input_1": 123123, "input_2": 345345},
+                "?_options=3%2C4%2C5&input_1=123123&input_2=345345&map_index=-1",
+            ),
+        ],
+        ids=[
+            "empty",
+            "single-option",
+            "multiple-options",
+            "single-param-input",
+            "multiple-options-and-param-inputs",
+        ],
+    )
+    @pytest.mark.parametrize("base_url", ["http://test", "http://test_2:8080"])
+    def test_generate_link_to_ui(
+        self,
+        dag_maker: DagMaker,
+        base_url: str,
+        options: list[str] | None,
+        params_input: dict[str, Any] | None,
+        expected_query_string: str,
+    ) -> None:
+        with dag_maker("test_dag"):
+            task = HITLOperator(
+                task_id="hitl_test",
+                subject="This is subject",
+                options=["1", "2", "3", "4", "5"],
+                body="This is body",
+                defaults=["1"],
+                respondents="test",
+                multiple=True,
+                params=ParamsDict({"input_1": 1, "input_2": 2, "input_3": 3}),
+            )
+        dr = dag_maker.create_dagrun()
+        ti = dag_maker.run_ti(task.task_id, dr)
+
+        expected_url = (
+            f"{base_url}/dags/test_dag/runs/test/tasks/hitl_test/required_actions{expected_query_string}"
+        )
+
+        url = task.generate_link_to_ui(
+            task_instance=ti,
+            base_url=base_url,
+            options=options,
+            params_input=params_input,
+        )
+        assert url == expected_url
+
+    @pytest.mark.parametrize(
+        "options, params_input, expected_query_string",
+        [
+            (None, None, "?map_index=-1"),
+            ("1", None, "?_options=1&map_index=-1"),
+            (["1", "2"], None, "?_options=1%2C2&map_index=-1"),
+            (None, {"input_1": 123}, "?input_1=123&map_index=-1"),
+            (
+                ["3", "4", "5"],
+                {"input_1": 123123, "input_2": 345345},
+                "?_options=3%2C4%2C5&input_1=123123&input_2=345345&map_index=-1",
+            ),
+        ],
+        ids=[
+            "empty",
+            "single-option",
+            "multiple-options",
+            "single-param-input",
+            "multiple-options-and-param-inputs",
+        ],
+    )
+    @conf_vars({("api", "base_url"): "http://localhost:8080/"})
+    def test_generate_link_fall_back_to_conf_api_base_url(
+        self,
+        dag_maker: DagMaker,
+        options: list[str] | None,
+        params_input: dict[str, Any] | None,
+        expected_query_string: str,
+    ) -> None:
+        with dag_maker("test_dag"):
+            task = HITLOperator(
+                task_id="hitl_test",
+                subject="This is subject",
+                options=["1", "2", "3", "4", "5"],
+                body="This is body",
+                defaults=["1"],
+                respondents="test",
+                multiple=True,
+                params=ParamsDict({"input_1": 1, "input_2": 2, "input_3": 3}),
+            )
+        dr = dag_maker.create_dagrun()
+        ti = dag_maker.run_ti(task.task_id, dr)
+
+        expected_url = f"http://localhost:8080/dags/test_dag/runs/test/tasks/hitl_test/required_actions{expected_query_string}"
+
+        url = task.generate_link_to_ui(
+            task_instance=ti,
+            options=options,
+            params_input=params_input,
+        )
+        assert url == expected_url
+
+    @pytest.mark.parametrize(
+        "options, params_input, expected_err_msg",
+        [
+            ([100, "2", 30000], None, "options {.*} are not valid options"),
+            (
+                None,
+                {"input_not_exist": 123, "no_such_key": 123},
+                "params {.*} are not valid params",
+            ),
+        ],
+    )
+    def test_generate_link_to_ui_with_invalid_input(
+        self,
+        dag_maker: DagMaker,
+        options: list[str] | None,
+        params_input: dict[str, Any] | None,
+        expected_err_msg: str,
+    ) -> None:
+        with dag_maker("test_dag"):
+            task = HITLOperator(
+                task_id="hitl_test",
+                subject="This is subject",
+                options=["1", "2", "3", "4", "5"],
+                body="This is body",
+                defaults=["1"],
+                respondents="test",
+                multiple=True,
+                params=ParamsDict({"input_1": 1, "input_2": 2, "input_3": 3}),
+            )
+        dr = dag_maker.create_dagrun()
+        ti = dag_maker.run_ti(task.task_id, dr)
+
+        with pytest.raises(ValueError, match=expected_err_msg):
+            task.generate_link_to_ui(task_instance=ti, options=options, params_input=params_input)
+
+    def test_generate_link_to_ui_without_base_url(
+        self,
+        dag_maker: DagMaker,
+    ) -> None:
+        with dag_maker("test_dag"):
+            task = HITLOperator(
+                task_id="hitl_test",
+                subject="This is subject",
+                options=["1", "2", "3", "4", "5"],
+                body="This is body",
+                defaults=["1"],
+                respondents="test",
+                multiple=True,
+                params=ParamsDict({"input_1": 1, "input_2": 2, "input_3": 3}),
+            )
+        dr = dag_maker.create_dagrun()
+        ti = dag_maker.run_ti(task.task_id, dr)

Review Comment:
   How about having another fixture to setup the Dag for generating link for UI and yield the `HITLOperator  instance`, `DagRun` and `TaskInstance`?
   It seems the Dags in these test cases are same.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(hitl): add utility functions for generating the url to required actions page [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on PR #54827:
URL: https://github.com/apache/airflow/pull/54827#issuecomment-3223773172

   Hey @jscheffl , I just rewrote the function with an example and doc update. Would be nice if you can take another look thanks!


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(hitl): add utility functions for generating the url to required actions page [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #54827:
URL: https://github.com/apache/airflow/pull/54827#discussion_r2303244889


##########
providers/standard/src/airflow/providers/standard/operators/hitl.py:
##########
@@ -87,12 +89,33 @@ def __init__(
         self.respondents = [respondents] if isinstance(respondents, str) else respondents
 
         self.validate_options()
+        self.validate_params()
         self.validate_defaults()
 
     def validate_options(self) -> None:
+        """
+        Validate the `options` attribute of the instance.
+
+        Raises:
+            ValueError: If `options` is empty.
+            ValueError: If any option contains a comma (`,`), which is not allowed.
+        """
         if not self.options:
             raise ValueError('"options" cannot be empty.')
 
+        if any("," in option for option in self.options):

Review Comment:
   Not really. it's part of the `__init__`. `__init__` raises error if `validate_options` does not pass. but I add a comment in the test cases. Thanks for reminder



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org