Skip to content

Airflow 2.2.3 : AirflowContextDeprecationWarning executing a DAG with PythonOperator that accesses the context #20603

Description

@gbonazzoli

Apache Airflow version

2.2.3 (latest released)

What happened

This strange behaviour started with Airflow 2.2.3, Airflow 2.2.2 was OK.

In every DAG that has a PythonOperator declared as:

def execute_Get_VMware_Host_Running_The_VM(ds, **kwargs):

    try:
        __VM_NAME__ = kwargs['dag_run'].conf['VM_NAME']
        logging.info(f"Remotely received value of {__VM_NAME__} for key=VM_NAME")
    except KeyError:
        errorMessage = 'This DAG must be RUN with VM_NAME parameter, es: {"VM_NAME":"lxd-p2c-server"}'
        raise KeyError(errorMessage)

with DAG('VMWARE_BACKUP',
          description = 'VMWARE_BACKUP',
          tags=['system'],
          schedule_interval = None,
          start_date = datetime(2019, 5, 29, tzinfo=local_tz),
          default_args = default_args,
          max_active_runs = 1,   # maximum number of active runs for this DAG
          concurrency = 1,       # The Airflow scheduler will run no more than concurrency task instances for your DAG at any given time. number of active runs for this DAG
          catchup = False
    ) as dag:

    Get_VMware_Host_Running_The_VM = PythonOperator(
        task_id = 'Get_VMware_Host_Running_The_VM',
        python_callable = execute_Get_VMware_Host_Running_The_VM,
        dag = dag
    )

we have the following WARNINGS in the log:

[2021-12-31, 02:00:02 CET] {warnings.py:109} WARNING - /usr/local/lib/python3.8/dist-packages/airflow/utils/context.py:152: AirflowContextDeprecationWarning: Accessing 'execution_date' from the template is deprecated and will be removed in a future version. Please use 'data_interval_start' or 'logical_date' instead.
  warnings.warn(_create_deprecation_warning(key, self._deprecation_replacements[key]))

[2021-12-31, 02:00:02 CET] {warnings.py:109} WARNING - /usr/local/lib/python3.8/dist-packages/airflow/utils/context.py:152: AirflowContextDeprecationWarning: Accessing 'next_ds' from the template is deprecated and will be removed in a future version. Please use '{{ data_interval_end | ds }}' instead.
  warnings.warn(_create_deprecation_warning(key, self._deprecation_replacements[key]))

[2021-12-31, 02:00:02 CET] {warnings.py:109} WARNING - /usr/local/lib/python3.8/dist-packages/airflow/utils/context.py:152: AirflowContextDeprecationWarning: Accessing 'next_ds_nodash' from the template is deprecated and will be removed in a future version. Please use '{{ data_interval_end | ds_nodash }}' instead.
  warnings.warn(_create_deprecation_warning(key, self._deprecation_replacements[key]))

[2021-12-31, 02:00:02 CET] {warnings.py:109} WARNING - /usr/local/lib/python3.8/dist-packages/airflow/utils/context.py:152: AirflowContextDeprecationWarning: Accessing 'next_execution_date' from the template is deprecated and will be removed in a future version. Please use 'data_interval_end' instead.
  warnings.warn(_create_deprecation_warning(key, self._deprecation_replacements[key]))

[2021-12-31, 02:00:02 CET] {warnings.py:109} WARNING - /usr/local/lib/python3.8/dist-packages/airflow/utils/context.py:152: AirflowContextDeprecationWarning: Accessing 'prev_ds' from the template is deprecated and will be removed in a future version.
  warnings.warn(_create_deprecation_warning(key, self._deprecation_replacements[key]))

[2021-12-31, 02:00:02 CET] {warnings.py:109} WARNING - /usr/local/lib/python3.8/dist-packages/airflow/utils/context.py:152: AirflowContextDeprecationWarning: Accessing 'prev_ds_nodash' from the template is deprecated and will be removed in a future version.
  warnings.warn(_create_deprecation_warning(key, self._deprecation_replacements[key]))

[2021-12-31, 02:00:02 CET] {warnings.py:109} WARNING - /usr/local/lib/python3.8/dist-packages/airflow/utils/context.py:152: AirflowContextDeprecationWarning: Accessing 'prev_execution_date' from the template is deprecated and will be removed in a future version.
  warnings.warn(_create_deprecation_warning(key, self._deprecation_replacements[key]))

[2021-12-31, 02:00:02 CET] {warnings.py:109} WARNING - /usr/local/lib/python3.8/dist-packages/airflow/utils/context.py:152: AirflowContextDeprecationWarning: Accessing 'prev_execution_date_success' from the template is deprecated and will be removed in a future version. Please use 'prev_data_interval_start_success' instead.
  warnings.warn(_create_deprecation_warning(key, self._deprecation_replacements[key]))

[2021-12-31, 02:00:02 CET] {warnings.py:109} WARNING - /usr/local/lib/python3.8/dist-packages/airflow/utils/context.py:152: AirflowContextDeprecationWarning: Accessing 'tomorrow_ds' from the template is deprecated and will be removed in a future version.
  warnings.warn(_create_deprecation_warning(key, self._deprecation_replacements[key]))

[2021-12-31, 02:00:02 CET] {warnings.py:109} WARNING - /usr/local/lib/python3.8/dist-packages/airflow/utils/context.py:152: AirflowContextDeprecationWarning: Accessing 'tomorrow_ds_nodash' from the template is deprecated and will be removed in a future version.
  warnings.warn(_create_deprecation_warning(key, self._deprecation_replacements[key]))

[2021-12-31, 02:00:02 CET] {warnings.py:109} WARNING - /usr/local/lib/python3.8/dist-packages/airflow/utils/context.py:152: AirflowContextDeprecationWarning: Accessing 'yesterday_ds' from the template is deprecated and will be removed in a future version.
  warnings.warn(_create_deprecation_warning(key, self._deprecation_replacements[key]))

[2021-12-31, 02:00:02 CET] {warnings.py:109} WARNING - /usr/local/lib/python3.8/dist-packages/airflow/utils/context.py:152: AirflowContextDeprecationWarning: Accessing 'yesterday_ds_nodash' from the template is deprecated and will be removed in a future version.
  warnings.warn(_create_deprecation_warning(key, self._deprecation_replacements[key]))

What you expected to happen

I think it is a bug.

How to reproduce

Run the code posted.

Operating System

Ubuntu 20.04.3 LTS

Versions of Apache Airflow Providers

apache-airflow-providers-celery==2.1.0
apache-airflow-providers-ftp==2.0.1
apache-airflow-providers-http==2.0.1
apache-airflow-providers-imap==2.0.1
apache-airflow-providers-microsoft-mssql==2.0.1
apache-airflow-providers-microsoft-winrm==2.0.1
apache-airflow-providers-openfaas==2.0.0
apache-airflow-providers-oracle==2.0.1
apache-airflow-providers-samba==3.0.1
apache-airflow-providers-sftp==2.3.0
apache-airflow-providers-sqlite==2.0.1
apache-airflow-providers-ssh==2.3.0

Deployment

Virtualenv installation

Deployment details

Airflow all in one

Anything else

nope

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions