You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "MatthieuBlais (via GitHub)" <gi...@apache.org> on 2023/07/21 02:26:01 UTC
[GitHub] [airflow] MatthieuBlais opened a new pull request, #32734: Add support for arrays of different data types in the Trigger Form UI
MatthieuBlais opened a new pull request, #32734:
URL: https://github.com/apache/airflow/pull/32734
### Description
The new Trigger Form UI released in 2.6 is handy but doesn't support `array` params of data types other than string. For more flexibility, this PR proposes to generate a JSON field similar to the `object` param if the users specify the attribute `items` in `schema`.
### How to reproduce the issue
Use an `array` param and require the items to be integers.
```
with DAG(
dag_id=Path(__file__).stem,
description=__doc__[0 : __doc__.find(".")],
doc_md=__doc__,
schedule=None,
start_date=datetime.datetime(2022, 3, 4),
catchup=False,
tags=["example_ui"],
params={
"array_of_numbers": Param(
[1, 2, 3],
"Only integers are accepted in this array",
type="array",
title="Array of numbers",
items={"type": "number"},
),
},
) as dag:
@task(task_id="show_params")
def show_params(**kwargs) -> None:
ti: TaskInstance = kwargs["ti"]
dag_run: DagRun = ti.dag_run
if not dag_run.conf:
print("Uups, no parameters supplied as DagRun.conf, was the trigger w/o form?")
raise AirflowSkipException("No DagRun.conf parameters supplied.")
print(f"This DAG was triggered with the following parameters:\n{json.dumps(dag_run.conf, indent=4)}")
show_params()
```
The Generated Conf JSON shows an array of strings
<img width="1132" alt="image" src="https://github.com/apache/airflow/assets/9677913/36191337-3676-4f61-aed5-24b278bffe95">
And we cannot trigger the DAG:
<img width="1162" alt="image" src="https://github.com/apache/airflow/assets/9677913/d8369464-8d77-4ce6-9c5b-9492e19a14c8">
### Workaround
We can manually update the Generated Configuration JSON box, but it is not user friendly (especially if we expect an array of objects!), and will become counter intuitive as users get used to the benefits of the new trigger form.
What do you think @jens-scheffler-bosch ?
--
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
[GitHub] [airflow] jens-scheffler-bosch commented on a diff in pull request #32734: Add support for arrays of different data types in the Trigger Form UI
Posted by "jens-scheffler-bosch (via GitHub)" <gi...@apache.org>.
jens-scheffler-bosch commented on code in PR #32734:
URL: https://github.com/apache/airflow/pull/32734#discussion_r1271306720
##########
docs/apache-airflow/core-concepts/params.rst:
##########
@@ -190,7 +190,8 @@ The following features are supported in the Trigger UI Form:
- ``boolean``: Generates a toggle button to be used as ``True`` or ``False``.
- ``date``, ``datetime`` and ``time``: Generate date and/or time picker
- ``array``: Generates a HTML multi line text field, every line edited will be made into a string array as value.
- if you add the attribute ``example`` with a list, a multi-value select option will be generated.
+ If you add the attribute ``example`` with a list, a multi-value select option will be generated.
+ If you add the attribute ``items``, a JSON entry field will be generated for more complex array types.
Review Comment:
Can you add a reference to JSON specs?
```suggestion
If you add the attribute ``items``, a JSON entry field will be generated for more array types
and additional type validation as described in
`JSON Schema Array Items<https://json-schema.org/understanding-json-schema/reference/array.html#items>`_.
```
##########
airflow/example_dags/example_params_ui_tutorial.py:
##########
@@ -208,6 +216,18 @@
title="JSON entry field",
section="Special advanced stuff with form fields",
),
+ "array_of_objects": Param(
+ [{"name": "account_name", "country": "country_name"}],
+ "Array with complex objects and validation rules",
Review Comment:
A link to JSON Schema specs might be useful here as well.
```suggestion
"Array with complex objects and validation rules. "
"See <a href='https://json-schema.org/understanding-json-schema"
"/reference/array.html#items'>JSON Schema validation options in specs.</a>",
```
--
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
[GitHub] [airflow] MatthieuBlais commented on pull request #32734: Add support for arrays of different data types in the Trigger Form UI
Posted by "MatthieuBlais (via GitHub)" <gi...@apache.org>.
MatthieuBlais commented on PR #32734:
URL: https://github.com/apache/airflow/pull/32734#issuecomment-1646865416
Great, thanks for the feedback! I've updated the PR with your commits
--
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
[GitHub] [airflow] jens-scheffler-bosch commented on pull request #32734: Add support for arrays of different data types in the Trigger Form UI
Posted by "jens-scheffler-bosch (via GitHub)" <gi...@apache.org>.
jens-scheffler-bosch commented on PR #32734:
URL: https://github.com/apache/airflow/pull/32734#issuecomment-1646940748
> Great, thanks for the feedback! I've updated the PR with your commits
Uuups, sorry, my comments were not syntax checked :-( The URL is not correctly formed to be accepted by Sphinx.
--
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
[GitHub] [airflow] eladkal merged pull request #32734: Add support for arrays of different data types in the Trigger Form UI
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal merged PR #32734:
URL: https://github.com/apache/airflow/pull/32734
--
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