Skip to content
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

map_index_template not compute when task marked success manually #39092

Open
1 of 2 tasks
raphaelauv opened this issue Apr 17, 2024 · 9 comments
Open
1 of 2 tasks

map_index_template not compute when task marked success manually #39092

raphaelauv opened this issue Apr 17, 2024 · 9 comments

Comments

@raphaelauv
Copy link
Contributor

raphaelauv commented Apr 17, 2024

Apache Airflow version

2.9.0

What happened?

If i mark a task manually at success while it's running only already succeed mapped task have a map_index_template

Screenshot from 2024-04-17 18-13-16

What you think should happen instead?

map_index_template

should be compute in all cases

How to reproduce

from airflow.operators.python import PythonOperator

from pendulum import today
from airflow import DAG

dag_1 = DAG(
    dag_id="dag_1",
    schedule_interval=None,
    max_active_tasks=2,
    start_date=today("UTC").add(days=-1)
)

with dag_1:
    def generate():
        return [{'date': '2024-01-01'}, {'date': '2024-01-02'}, {'date': '2024-01-03'}, {'date': '2024-01-04'},
                {'date': '2024-01-05'}, {'date': '2024-01-06'}, {'date': '2024-01-07'}]


    def toto(date, arg_2=None):
        import time
        print(date)
        time.sleep(10)


    a = PythonOperator(
        task_id="a",
        python_callable=generate)
    b = PythonOperator.partial(
        task_id="b",
        map_index_template="{{ task.op_kwargs['date'] }}",
        python_callable=toto).expand(op_kwargs=a.output)

    a >> b

trigger a run , wait for a mapped task to succes , then mark state of the task b at success

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@raphaelauv raphaelauv added area:core kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet labels Apr 17, 2024
@RNHTTR
Copy link
Contributor

RNHTTR commented Apr 17, 2024

This might be fixed by #38902 . It might require adding some logic to render mapped tasks in set_task_instance_state, which I believe is called when manually setting a task instance's state.

@RNHTTR RNHTTR added area:dynamic-task-mapping AIP-42 and removed needs-triage label for new issues that we didn't triage yet labels Apr 17, 2024
@karenbraganz
Copy link

I would like to be assigned this issue.

karenbraganz added a commit to karenbraganz/airflow that referenced this issue May 2, 2024
@raphaelauv
Copy link
Contributor Author

@karenbraganz are you still working on this issue ? thanks

@karenbraganz
Copy link

I created a draft PR but was informed that rendering the Jinja template on the webserver is not viable. @uranusjr could you please clarify why this is the case? I accidentally closed the PR before I could get a complete explanation from you. Here is the PR for reference: #39505

@raphaelauv
Copy link
Contributor Author

accidentally closed the PR you can't re-open it ?

@karenbraganz
Copy link

I did not re-open it because it looks like the functionality is not viable. The only thing left was for @uranusjr to provide an explanation of why they think it's not viable, which is why I have tagged them here for an explanation.

@raphaelauv
Copy link
Contributor Author

could you please tell @RNHTTR if it's okay to unassign you

@uranusjr
Copy link
Member

Rendering Jinja templates in the webserver means injecting custom user logic into protected Airflow services, which is not acceptable. Rendering must happen in the worker. A fix along the line mentioned in Ryan’s comment above is more likely correct, although I am not sure (and never checked) where exactly the rendering should happen.

@karenbraganz
Copy link

I got the error referenced in my PR after adding my rendering logic to set_task_instance_state() in models/dag.py. I just tried adding the logic to _set_state() (from models/taskinstance.py) which is called by set_task_instance_state() in www/views.py and am getting the same error. I'm not sure how to get the worker to execute the code at the moment, so I will unassign myself.

@karenbraganz karenbraganz removed their assignment Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants