Dag.test causes Logging Recurison when run as a Python Task (Celery) #30107
Replies: 2 comments
-
I was wrong, non-dynamic dags also break. You can try the same def test_nondynamic_dag():
from airflow.example_dags.tutorial_dag import dag
dag.test() Also triggers the infinite logging. |
Beta Was this translation helpful? Give feedback.
-
Yes. This is how currently logging works in released version - it takes the stdout and redirect it to logger inside task. If there is another redirection done with pytest done in the same process (whit ch pytest does by default) it will recurse because stdout that it gets is already a logger effectively. What you can try to do, is to run pytest as subprocess or disable any log redirection by pytest (you should look up in pytest options and try what works). Also we are doing some improvements to upcoming 2.6 version and it might change the behaviour - it would be best if you try the main version and see if it behaves better. For now I am converting it to to a discussion in case more is needed. |
Beta Was this translation helpful? Give feedback.
-
Apache Airflow version
2.5.1
What happened
Executor: Celery
Airflow V 2.5.1
Platform: Python 3.9
OS: ubuntu20.04
Hi team, this one is pretty wild.
In order to integrate with our CICD, we run Pytest as a Task inside a Dag like so
This has been working great! And I was excited to use the new
dag.test
command to run our test dags inside the pipeline. Unfortunately, if youdag.test
any Dag with dynamically mapped tasks, the logging system triggers a recursive exception.You can easily recreate this behavior by creating the following test case
And then executing it as a task using the above
run_pytest
. You'll see a stack trace likeetc etc. You can see the cycle between
flush
andpropagate_log
What you think should happen instead
It would be nice to be able to run a Dag.test command inside a PythonOperator Task so we can easily run pytest as a remotely triggered Dag.
How to reproduce
Operating System
ubuntu20.04
Versions of Apache Airflow Providers
You don't need any providers to reproduce
Deployment
Docker-Compose
Deployment details
Running scheduler, worker, webserver, and Redis, are inside a local docker compose. Single worker container with default Celery settings.
Anything else
No response
Are you willing to submit PR?
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions