ashb commented on issue #5574: [AIRFLOW-4941] Warn that default_args not 
applied via setter
URL: https://github.com/apache/airflow/pull/5574#issuecomment-511393939
 
 
   Okay I tried out my idea and it works with one caveat.
   
   If you define a custom operator and _don't_ decorate with `@apply_defaults` 
it won't work.
   
   ```python
           class Op(BaseOperator):
               @apply_defaults
               def __init__(self, x=None, **kwargs):
                   super().__init__(**kwargs)
                   self._x = x
   
           class SubclassWithoutApplyDefaults(BaseOperator):
               def __init__(self, **kwargs):
                   super().__init__(**kwargs)
   
           dag = DAG(
               'dag',
               default_args={
                   'email_on_failure': False,
                   'email': 'example@localhost',
                   'x': 'x',
               },
               start_date=airflow.utils.dates.days_ago(2),
           )
   
           op = Op(
               task_id='op',
               email_on_failure=True,  # happen to be the same as the default 
value in __init__ signature
           )
   
           op.dag = dag
   
           self.assertTrue(op.email_on_failure)
           self.assertEqual(op.email, 'example@localhost')
           # Test that we re-call __init__ with the new default args
           self.assertEqual(op._x, 'x')
   
           op = SubclassWithoutApplyDefaults(
               task_id='op',
               email_on_failure=True,  # happen to be the same as the default 
value in __init__ signature
           )
   
           op.dag = dag
   
           self.assertTrue(op.email_on_failure)
           self.assertEqual(op.email, 'example@localhost') # This fails
   ```
   
   Do you think that edge case is worth it? Is this a better place than we are 
now?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to