GitHub user raphaelauv added a comment to the discussion: Pass triggering user
information to DAG
working solution with airflow 3.3.1
```python
from airflow.sdk import DAG, get_current_context, CronDataIntervalTimetable,
timezone
from airflow.providers.standard.operators.python import PythonOperator
def print_triggering_user() -> None:
context = get_current_context()
dag_run = context.get("dag_run")
print(f"Run ID: {dag_run.run_id}")
print(f"Run type: {dag_run.run_type}")
# Populated for UI/API-triggered runs by an authenticated user.
# None for scheduler/backfill-triggered runs.
triggering_user = dag_run.triggering_user_name
if triggering_user:
print(f"Triggering user: {triggering_user}")
else:
print("Triggering user: N/A (not a user-triggered run)")
with DAG(
dag_id="print_triggering_user_dag",
schedule=CronDataIntervalTimetable("0 0 1 * *", "Europe/Paris"),
start_date=timezone.parse("2026-07-05T00:00:00", "Europe/Paris"),
catchup=False,
):
print_user_task = PythonOperator(
task_id="print_triggering_user",
python_callable=print_triggering_user,
)
```
GitHub link:
https://github.com/apache/airflow/discussions/24812#discussioncomment-18078052
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]