cansjt edited a comment on issue #17022:
URL: https://github.com/apache/airflow/issues/17022#issuecomment-891787393


   With Airflow 2.1.2 we are something similar but not identical:
   ```
   Task failed with exception", "exc_info": "Traceback (most recent call last):
     File 
\"/usr/local/lib/python3.8/site-packages/airflow/models/taskinstance.py\", line 
1157, in _run_raw_task
       self._prepare_and_execute_task_with_callbacks(context, task)
     File 
\"/usr/local/lib/python3.8/site-packages/airflow/models/taskinstance.py\", line 
1331, in _prepare_and_execute_task_with_callbacks
       result = self._execute_task(context, task_copy)
     File 
\"/usr/local/lib/python3.8/site-packages/airflow/models/taskinstance.py\", line 
1361, in _execute_task
       result = task_copy.execute(context=context)
     File 
\"/usr/local/lib/python3.8/site-packages/airflow/operators/python.py\", line 
150, in execute
       return_value = self.execute_callable()
     File 
\"/usr/local/lib/python3.8/site-packages/airflow/operators/python.py\", line 
161, in execute_callable
       return self.python_callable(*self.op_args, **self.op_kwargs)
     File 
\"/usr/local/lib/python3.8/site-packages/aggregator/tasks/airflow.py\", line 
58, in __call__
       super().__call__(execution_date + timedelta(days=1), **context)
     File 
\"/usr/local/lib/python3.8/site-packages/aggregator/tasks/__init__.py\", line 
103, in __call__
       start_date, end_date = self._period(execution_date, **context)
     File \"/usr/local/lib/python3.8/site-packages/aggregator/retention.py\", 
line 189, in __call__
       lower_bounds, upper_bounds = zip(*[w(execution_date, **context) for w in 
self._windows])
     File \"/usr/local/lib/python3.8/site-packages/aggregator/retention.py\", 
line 189, in <listcomp>
       lower_bounds, upper_bounds = zip(*[w(execution_date, **context) for w in 
self._windows])
     File 
\"/usr/local/lib/python3.8/site-packages/aggregator/tasks/airflow.py\", line 
77, in __call__
       if task_instance is None or 
task_instance.previous_execution_date_success is None:
   AttributeError: 'TaskInstance' object has no attribute 
'previous_execution_date_success'
   ```
   The code triggering the execution is this
   ```python
   class FromLastRunWindow(TimeWindow):
       def __init__(self,  *, clamp: bool = True, **kwargs):
           super().__init__(**kwargs)
           self._clamp = clamp
   
       def __call__(self, execution_date: datetime, **context) -> 
Tuple[datetime, datetime]:
            upper = datetime.max
            if self._clamp:
                upper = self._fix_date(execution_date)
            task_instance = context.get('task_instance')
           if task_instance is None or 
task_instance.previous_execution_date_success is None:  # Raises here
                return datetime.min, upper
           return 
datetime.combine(task_instance.previous_execution_date_success.date(),
                                    time(0, 0, 0, 0)), upper
   ```
   This is an auxiliary function we use in various tasks, as follows:
   ```python
   def python_operator_callable(execution_date, **context):
       start, end = FromLastRunWindow()(execution_date, **context)
       # Proceed with the tasks operations ...
   ```
   Works fine with 1.10.15. Looking at the documentation (versions 1.10.15, 
2.0.0 & 2.12) it seems the `TaskInstance.previous_execution_date_success` has 
simply been removed, without any deprecation notice. And the proper way to 
retrieve the same info is the new API @josh-fell used in is example (the 
`TaskInstance.get_previous_execution_date()` method) 
   
   So the question is more will this be a *wontfix*, forcing anyone depending 
on this to update their code or is it worth a PR ? Something more or less like:
   ```py
   class TaskInstance(...):
       @property
       def previous_execution_date_success(self):
           """The execution_date of the instance of this of this task from 
latest succesful dag run.
           
           .. deprecated:: 2.1.3
   
              This property will be removed in Airflow 2.y.0
           """
           warnings.warn('The `TasksInstance.previous_execution_date_success` 
has been deprecated '
                         'and will be removed in Airflow 2.y.0. Use '
                         
'TaskInstance.get_previous_execution_date(state=State.SUCCESS)` instead.',
                         DeprecationWarning)
           return self.get_previous_execution_date(state=State.SUCCESS)
   ```


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