ErandM50 opened a new issue, #39997:
URL: https://github.com/apache/airflow/issues/39997

   ### Apache Airflow version
   
   Other Airflow 2 version (please specify below)
   
   ### If "Other Airflow 2 version" selected, which one?
   
   2.90
   
   ### What happened?
   
   In trying to optimize dynamic DAG generation, I tried to employ the method 
described 
[here](https://airflow.apache.org/docs/apache-airflow/stable/howto/dynamic-dag-generation.html#optimizing-dag-parsing-delays-during-execution),
 I applied the docs code while running Airflow with a LocalExecutor
   
   ```
   from airflow.models.dag import DAG
   from airflow.utils.dag_parsing_context import get_parsing_context
   
   current_dag_id = get_parsing_context().dag_id
   
   for thing in list_of_things:
       dag_id = f"generated_dag_{thing}"
       if current_dag_id is not None and current_dag_id != dag_id:
           continue  # skip generation of non-selected DAG
   
       with DAG(dag_id=dag_id, ...):
           ...
   ```
   
   in all cases current_dag_id was None even during execution.
   Not sure if this is a bug or a feature since while using LocalExecutor the 
scheduler process runs the tasks. 
   
   I switched to CeleryExecutor in the same environment and the same code 
worked.
   
   ### What you think should happen instead?
   
   `get_parsing_context().dag_id` should return the dag_id during execution 
time.
   
   ### How to reproduce
   
   Run the code with the LocalExecutor on a test dag. Trigger the dag yourself 
and log current_dag_id. It will be None even though this was during dag 
execution.
   
   ### Operating System
   
   ubuntu 22.04
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Virtualenv installation
   
   ### Deployment details
   
   _No response_
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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