Skip to content

Empty Param value doesn't propagate to JSON #31869

Description

@BasPH

Apache Airflow version

2.6.1

What happened

I'm using array Params and sometimes want to provide no values.

The Param is configured with type=["array", "null"] and a default value (e.g. ["a", "b", "c"]). I would assume emptying the Param field would set an empty array or null in the generated configuration JSON, but instead Airflow sets the default value. I have to manually modify the generated configuration JSON to submit an empty array.

Normal usage:
image

Clearing the param field sets the default value:
image

I have to manually modify the generated configuration JSON:
image

What you think should happen instead

I expect Airflow to set an empty array or null value when a Param field is left empty (and null is set as Param type).

How to reproduce

import datetime

from airflow.decorators import dag, task
from airflow.exceptions import AirflowSkipException
from airflow.models import Param


@dag(
    schedule=None,
    start_date=datetime.datetime(2023, 1, 1),
    params={
        "demo": Param(
            default=["a", "b", "c"],
            type=["array", "null"],
        )
    },
)
def dagrun_conf():
    @task
    def print_params(params=None):
        if params["demo"]:
            print(params["demo"])
        else:
            raise AirflowSkipException("Nothing to do here")

    print_params()


dagrun_conf()

Operating System

N/A

Versions of Apache Airflow Providers

No response

Deployment

Astronomer

Deployment details

No response

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Labels

_eol_affected_version:2.6Issues Reported for 2.6area:UIRelated to UI/UX. For Frontend Developers.javascriptPull requests that update Javascript codekind:bugThis is a clearly a bugpriority:lowBug with a simple workaround that would not block a release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions