-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Bugfix: Move rendering of map_index_template so it renders for failed tasks as long as it was defined before the point of failure
#38902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
RNHTTR
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for cleaning up my mess :)
render template regardless of task outcome
uranusjr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix tests
|
This should fix things… |
|
@uranusjr thank you! |
|
I wonder what I've experienced is same type of the problem above:
In this case, all map_index values are integer, instead of given names. |
|
@rightx2 That is interesting. I just tried that and for me the map index values from the first run "stick", but maybe I misunderstood what you are doing :) This is what I tried: This is the DAG: from airflow.decorators import dag, task
@dag(
start_date=None,
schedule=None,
catchup=False,
)
def mapping_test():
@task(
map_index_template="{{ custom_map_index }}"
)
def add_one(num):
import time
if num > 10:
time.sleep(10)
else:
time.sleep(2)
from airflow.operators.python import get_current_context
context = get_current_context()
context["custom_map_index"] = "Input x=" + str(num)
return num + 1
add_one.expand(num=[1, 2, 3, 4, 5, 10, 11, 12, 13])
mapping_test()I'm using Airflow 2.9.1 (Astro Runtime 11.3.0) |
|
I think there was a mistake in my experiment. I believe I can clarify it now.
|
|
@rightx2 Thanks for the added explanation. I understand what you mean now and can reproduce it, marking as success (or as failed) will lead to an integer index even if the code to define the custom map index has already run. Thanks for flagging this! @RNHTTR I think it would be nice if it worked for marking tasks the same way as for failed tasks with attempting to render the custom map index template even if interrupted. :) |


In Airflow 2.9
map_index_templatedoes not render when the task fails.I moved the rendering into the
finallyof_execute_callableso it always happens.TaskFlow:

Traditional operator:

Also attempted 2 unit tests :)
Apologies if there is already a PR addressing this. I did not see one.
cc: @RNHTTR
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in newsfragments.