kaxil commented on issue #51816:
URL: https://github.com/apache/airflow/issues/51816#issuecomment-2980512138

   @opeida The ideal way would be to not access Variables or Connections at the 
top of your file (i.e outside Task Context). In your case, you can rewrite the 
dag as follows:
   
   
   
   ```py
   import logging
   
   from airflow import DAG
   from airflow.providers.standard.operators.empty import EmptyOperator
   from airflow.providers.standard.operators.python import PythonOperator
   
   
   def my_function(my_var: str) -> None:
       logging.getLogger(__name__).info(my_var)
   
   with DAG("test_dag") as dag:
   
       start = EmptyOperator(task_id="start")
   
       py_func = PythonOperator(
           task_id="py_func",
           python_callable=my_function,
           op_kwargs={
               "my_var": {{ var.value.my_variable }}
           }
       )
   
       end = EmptyOperator(task_id="end")
   
       start >> py_func >> end
   
   if __name__ == "__main__":
       dag.test()
   ```


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