vasanthrpjan1-boop opened a new pull request, #61643:
URL: https://github.com/apache/airflow/pull/61643

   ## Summary
   
   - Adds a `CallbackSource` str enum (`"dag"` / `"task"`) to 
`airflow.sdk.definitions.context`
   - Injects `context["callback_source"]` in all four callback invocation paths 
so shared callback functions can tell whether they were triggered at the DAG 
level or the task level
   - Adds the field to the `Context` TypedDict as `NotRequired` (only present 
during callbacks, not during normal template rendering)
   - Exports `CallbackSource` from `airflow.sdk` for easy user access
   
   ### Usage example
   
   ```python
   from airflow.sdk import CallbackSource
   
   def my_callback(context):
       if context["callback_source"] == CallbackSource.DAG:
           notify_team(f"DAG run finished: {context['reason']}")
       else:
           notify_team(f"Task {context['ti'].task_id} finished")
   ```
   
   ## Test plan
   
   - [x] New test `test_task_callback_context_has_callback_source` covers 
success and failure task callbacks
   - [x] Assertions added to existing 
`test_execute_dag_callbacks_with_context_from_server` and 
`test_execute_dag_callbacks_without_context_from_server`
   - [x] Assertion added to existing 
`test_execute_task_callbacks_failure_callback`
   
   Closes #61119
   
   Made with [Cursor](https://cursor.com)


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