uranusjr commented on issue #17073:
URL: https://github.com/apache/airflow/issues/17073#issuecomment-882191138


   A DAG-level solution feels limiting to me. While it sounds convenient, it is 
not actually very often a user would want the same hook to be executed for 
every task, so you’d probably end up with a lot of if-else in the function to 
handle different tasks in the end. A better approach to me would be to allow 
supplying the hook without subclassing, something like
   
   ```python
   def pre_exec(task: BaseOperator, context: Any) -> None:
       ...
   
   def different_pre_exec(task: BaseOperator, context: Any) -> None:
       ...
   
   with DAG(...) as dag:
       t1 = BashOperator(
           ...,
           before_exec_hook=pre_exec,
       )
       t2 = BaseOperator(
           ...,
           before_exec_hook=pre_exec,
       )
       t3 = BaseOperator(
           ...,
           before_exec_hook=different_pre_exec,
       )
   ```


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