The GitHub Actions job "Build images for Reuse _run_task_session in mapped 
render_template_fields https://github.com/apache/airflow/pull/33309
" on airflow.git has succeeded.
Run started by GitHub user potiuk (triggered by potiuk).

Head commit for run:
8ba9e888533e08c67c1cc4bef0617fb32c4206c8 / Jarek Potiuk <[email protected]>
Reuse _run_task_session in mapped render_template_fields

The `render_template_fields` method of mapped operator needs to use
database session object to render mapped fields, but it cannot
get the session passed by @provide_session decorator, because it is
used in derived classes and we cannot change the signature without
impacting those classes.

So far it was done by creating new session in mapped_operator, but
it has the drawback of creating an extra session while one is
already created (remnder_template_fields is always run in the
context of task run and it always has a session created already
in _run_raw_task). It also causes problems in our tests where
two opened database session accessed database at the same time
and it cases sqlite exception on concurrent access and mysql
error on running operations out of sync - likely when the same
object was modified in both sessions.

This PR changes the approach - rather than creating a new session
in the mapped_operator, we are retrieving the session from one
stored by the _run_raw_task. It is done by context manager and
adequate protection has been added to make sure that:

a) the call is made within the context manager
b) context manageer is never initialized twice in the same
   call stack

After this change, resources used by running task will be smaller,
and mapped tasks will not always open 2 DB sesions.

Fixes: #33178

Report URL: https://github.com/apache/airflow/actions/runs/5843348904

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to