question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

apply_defaults doesn't run for decorated task

See original GitHub issue

Apache Airflow version: 2.1

Kubernetes version (if you are using kubernetes) (use kubectl version): N/A

Environment:

  • Cloud provider or hardware configuration:
  • OS (e.g. from /etc/os-release): Ubuntu 18.04.5 LTS
  • Kernel (e.g. uname -a): Linux 4.4.0-18362-Microsoft #1049-Microsoft Thu Aug 14 12:01:00 PST 2020 x86_64 x86_64 x86_64 GNU/Linux
  • Install tools:
  • Others:

What happened: The apply_defaults doesn’t work for decorated tasks after upgrading to Airflow 2.1.

What you expected to happen: Missing task arguments to be filled by values from DAG default_args. Airflow 2.1 expected to apply by default (https://github.com/apache/airflow/pull/15667) but doesn’t work either with or without apply_defaults decorator being used.

How to reproduce it: Sample DAG attached as txt file. task_decorator_test.txt

If run in Airflow 2.0.2, this prints in the logs the conn_id value showing that it was picked up from the DAG default_args. image

If run in Airflow 2.1, this causes TypeError for missing required argument in the scheduler. If a default value is given to the argument, (making it optional), the task can run, but the apply_defaults to use the DAG’s default_args value doesn’t run. image

Anything else we need to know: issue happens with Airflow 2.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
junnpluscommented, Jun 11, 2021

@jedcunningham yes, I think it fixed.

1reaction
junnpluscommented, May 26, 2021

apply_default is moved to metaclass of operator, it not process the signature of the python_callable for DecoratedOperator to fill in op_kwargs.

We can preprocess the padding of default_args before https://github.com/apache/airflow/blob/master/airflow/decorators/base.py#L206 like dag decorator.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a custom Operator - Apache Airflow
Use @apply_defaults decorator function to fill unspecified arguments with default_args . You can specify the default_args in the dag file.
Read more >
Creating a custom Operator - Apache Airflow Documentation
Use @apply_defaults decorator function to fill unspecified arguments with default_args . You can specify the default_args in the dag file.
Read more >
Why doesn't anyone release library of "@task" decorated ...
This example works fine and @task decorated functions can be declared not only inside dag and can be reused. from airflow.operators.python ...
Read more >
[AIRFLOW-8057] [AIP-31] Add @task decorator
Airflow doesn't allow dynamic operators (execute 1 operator several ... Review comment: Defining a task decorated operator without a DAG and ...
Read more >
Introduction to Airflow decorators | Astronomer Documentation
How to use Airflow decorators​ · For any decorated object in your DAG file, you must call them so that Airflow can register...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found