Skip to content

DAG Param incorrectly convert enum objects to strings #42524

Open
@cdabella

Description

Apache Airflow version

2.10.1

If "Other Airflow 2 version" selected, which one?

No response

What happened?

Using a DAG Param with a type of object and enum set to a list of possible objects is reflected as a string in Trigger DAG UI, both in the selector and in the underlying JSON.
image

When attempting to run the DAG using the value, the DAG will fail to run
image

What you think should happen instead?

JSON schemas support enums of any type

Elements in the array might be of any type, including null.

(source: https://json-schema.org/draft/2020-12/json-schema-validation#section-6.1.2-3) . They should be configurable and supported by DAG Parameters, and should allow for successful selection and execution of the DAG from the Trigger DAG UI.

How to reproduce

Create the following DAG

from airflow.decorators import dag, task
from pendulum import datetime
from airflow.models.param import Param

keys = ["a", "b", "c"]
values_display_list = [{"key": key, "value": key.upper()} for key in keys]


@dag(
    start_date=datetime(2024, 1, 1),
    schedule=None,
    catchup=False,
    params={
        "x": Param(
            values_display_list[0],
            type=["object"],
            enum=values_display_list,
        ),
    },
    tags=["example"],
)
def example_params():
    @task
    def example_params_task(*, params, **kwargs) -> None:
        if params:
            print(f"Params: {params}")
        else:
            print("No Params")

    example_params_task()


# Instantiate the DAG
example_params()

Operating System

Debian 12 (Bookworm)

Versions of Apache Airflow Providers

apache-airflow==2.10.1+astro.1

Deployment

Other Docker-based deployment

Deployment details

Astro CLI running Astro Runtime 12.1.0

Anything else?

I think this issue might be caused by the the trigger templating at https://github.com/apache/airflow/blob/2.10.2/airflow/www/templates/airflow/trigger.html#L77-L86

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Assignees

No one assigned

    Labels

    area:UIRelated to UI/UX. For Frontend Developers.type:improvementChangelog: Improvements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions