kaxil opened a new pull request, #73260:
URL: https://github.com/apache/airflow/pull/73260

   `test_env_vars_rendered_for_mapped_task`, added in #71174, renders a 
`MappedOperator`'s template fields outside a task run. On Airflow 2 that render 
takes its session from a module global that 
[`get_current_task_instance_session`](https://github.com/apache/airflow/blob/2.11.1/airflow/utils/task_instance_session.py#L37-L49)
 fills in on demand and never clears, so the test leaves a session behind and 
the next `TaskInstance.run()` anywhere in the same pytest process fails in 
[`_run_raw_task`](https://github.com/apache/airflow/blob/2.11.1/airflow/models/taskinstance.py#L276)
 with `RuntimeError: Session already set for this task`.
   
   The `Compat 2.11.1` provider job runs every provider in one pytest process, 
so the fallout lands wherever a `TaskInstance.run()` happens to be collected 
later: 50 failures in common.sql and docker, the `--maxfail` cap, none of them 
in the provider that caused it ([example 
run](https://github.com/apache/airflow/actions/runs/35158093683/job/105006115260)).
   
   Wrapping the render in `set_current_task_instance_session` clears the global 
on the way out. That pairing is Airflow 2's own way of rendering outside a task 
run -- [`airflow tasks 
render`](https://github.com/apache/airflow/blob/2.11.1/airflow/cli/commands/task_command.py#L726)
 does exactly this -- and Airflow 3 renders without a session at all, so the 
Airflow 3 branch is a no-op and the test keeps asserting the rendered env var 
name on both versions instead of being skipped on 2.
   
   **The same trap stays open for any other provider test that renders a mapped 
task.** The shared `render_template_fields` helper in `devel-common` reaches 
the same accessor on its pre-3.2 branch, and `providers/standard` works around 
it with a local autouse fixture that resets the global. Centralising that is 
worth doing, but it would not fix this call site, which renders through the 
operator directly, so this change stays at the one site breaking main.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to