Skip to content

Importing taskflow functions from a library #23937

Discussion options

You must be logged in to vote

Hey @MatrixManAtYrService! With 2.3, there was a new override() method added to decorators which might help here. You are now able to assign task-level (BaseOperator-level) params without directly setting them in the decorator explicitly.

Your example could now be written as:

# lib.py
from airflow.decorators import task

@task
def incr(x):
    return x + 1
# dag.py
from include.lib import incr
from pendulum import datetime

from airflow.decorators import dag

@dag(start_date=datetime(2022, 1, 1), schedule_interval=None)
def my_dag():
    first_incr = incr.override(retries=5)(1)
    incr.override(retries=2)(first_incr)

_ = my_dag()

Of course, if you didn't want your lib functions to requi…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MatrixManAtYrService
Comment options

Answer selected by MatrixManAtYrService
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants