sk-shakeel commented on issue #46418:
URL: https://github.com/apache/airflow/issues/46418#issuecomment-2705273899

   Hi @potiuk @amoghrajesh ,
   Since I have been looking the code of python operator I noticed that there 
in no initialization of environment variables from context.
   As well when I have look into the code of bash operator there is 
initialization of environment variables from context(Correct me if Iam wrong!). 
Keeping this aside, the question  rises is do we really want the same 
implementation for python operator? 
   As far as I see conext can be accessed through **kwargs** in python 
operator. The below python callable is an example for that. 
   
   ```
   def my_python_task(**kwargs):
       context_vars = {
           "AIRFLOW_CTX_DAG_ID": kwargs["dag"].dag_id,
           "AIRFLOW_CTX_TASK_ID": kwargs["task"].task_id,
           "AIRFLOW_CTX_TRY_NUMBER": kwargs["ti"].try_number,
           "AIRFLOW_CTX_DAG_RUN_ID": kwargs["dag_run"].run_id,
       }
       logging.info(f"Exporting env vars: {context_vars}")
   
   ```


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