dheerajturaga commented on PR #51738:
URL: https://github.com/apache/airflow/pull/51738#issuecomment-3006286559

   @ashb, our use case basically has many users triggering a single dag with 
different parameters. Its hard to identify which dag run was triggered by whom 
when you have a lot of dag runs being triggered (which is our usecase) 
   
   to work around this in Airflow 2, we were doing something like this: 
   
   ```
   @task(task_id="owner", execution_timeout=timedelta(minutes=10))
   def find_owner(dag_run=None) -> str:
       """
       Identify user/owner who triggered a DAG.
       """
       with create_session() as s:
           user = s.query(Log).filter(
               Log.dag_id == dag_run.dag_id,
               Log.event == 'trigger',
               Log.run_id == dag_run.run_id).one().owner
           if user and 'airflow' in user:
               logger.warning(f"System account trigger: {user}")
           return user
    ````
   
   having the triggering user readily available in the task allows us many 
different things. Say for example:
   - put some breadcrums in the logfiles we generate regarding who triggered 
the task.
   - allows us to run the dag instance as the triggering user ( something 
similar to `run_as_user` ) .. etc 


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to