Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions airflow-core/docs/core-concepts/params.rst
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ The following features are supported in the Trigger UI Form:
* ``format="multiline"``: Generate a multi-line textarea
* | ``enum=["a", "b", "c"]``: Generates a
| drop-down select list for scalar values.
| If the choices come from an external config file,
| read that file while the Dag is parsed and pass the
| resulting list to ``enum``; the trigger form reads
| the serialized Dag Params and does not call dynamic
| choice providers when the form opens.
| As of JSON validation, a value must be
| selected or the field must be marked as
| optional explicit. See also details inside
Expand Down
1 change: 1 addition & 0 deletions airflow-core/newsfragments/71180.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Documented how to populate enum Dag Params from external config files for the trigger Dag form.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.

[InterfaceA]
TYPE = Script

[InterfaceB]
TYPE = EBICS

[InterfaceC]
TYPE = Script
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@

from __future__ import annotations

import configparser
import datetime
import json
from pathlib import Path

from airflow.sdk import DAG, Param, task


def _get_script_interfaces_from_config() -> list[str]:
config = configparser.ConfigParser()
config.read(Path(__file__).with_name("example_params_ui_interfaces.ini"))

return [section for section in config.sections() if config[section].get("TYPE") == "Script"]


SCRIPT_INTERFACES = _get_script_interfaces_from_config()

with DAG(
dag_id=Path(__file__).stem,
dag_display_name="Params UI tutorial",
Expand Down Expand Up @@ -75,6 +86,19 @@
enum=[f"value {i}" for i in range(16, 64)],
section="Typed parameters with Param object",
),
"script_interface": Param(
SCRIPT_INTERFACES[0],
schema={
"type": "string",
"title": "Script interface",
"description": "Choices are generated from example_params_ui_interfaces.ini at Dag parse time.",
"enum": SCRIPT_INTERFACES,
"values_display": {
name: name.replace("Interface", "Interface ") for name in SCRIPT_INTERFACES
},
"section": "Typed parameters with Param object",
},
),
# [END section_1]
# Boolean as proper parameter with description
"bool": Param(
Expand Down