feluelle commented on a change in pull request #7900: Convert properties with
query to real methods
URL: https://github.com/apache/airflow/pull/7900#discussion_r402376564
##########
File path: airflow/models/taskinstance.py
##########
@@ -596,28 +602,80 @@ def _get_previous_ti(
return None
@property
- def previous_ti(self) -> Optional['TaskInstance']:
- """The task instance for the task that ran before this task
instance."""
- return self._get_previous_ti()
+ def previous_ti(self):
+ """
+ This attribute is deprecated.
+ Please use `airflow.models.taskinstance.TaskInstance.get_previous_ti`
method.
+ """
+ warnings.warn(
+ """
+ This attribute is deprecated.
+ Please use
`airflow.models.taskinstance.TaskInstance.get_previous_ti` method.
+ """,
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.get_latest_execution_date()
@property
def previous_ti_success(self) -> Optional['TaskInstance']:
- """The ti from prior succesful dag run for this task, by execution
date."""
+ """
+ This attribute is deprecated.
+ Please use `airflow.models.taskinstance.TaskInstance.get_previous_ti`
method.
+ """
+ warnings.warn(
+ """
+ This attribute is deprecated.
+ Please use
`airflow.models.taskinstance.TaskInstance.get_previous_ti` method.
+ """,
+ DeprecationWarning,
+ stacklevel=2,
+ )
return self._get_previous_ti(state=State.SUCCESS)
- @property
- def previous_execution_date_success(self) -> Optional[pendulum.datetime]:
- """The execution date from property previous_ti_success."""
- self.log.debug("previous_execution_date_success was called")
- prev_ti = self._get_previous_ti(state=State.SUCCESS)
+ def get_previous_execution_date(
+ self,
+ state: Optional[str] = None,
+ session: Session = None,
+ ) -> Optional[pendulum.datetime]:
+ """
+ The execution date from property previous_ti_success.
+
+ :param state: If passed, it only take into account instances of a
specific state.
+ """
+ self.log.debug("previous_execution_date was called")
+ prev_ti = self.get_previous_ti(state=state, session=session)
return prev_ti and prev_ti.execution_date
+ def get_previous_start_date(
+ self,
+ state: Optional[str] = None,
+ session: Session = None
+ ) -> Optional[pendulum.datetime]:
+ """
+ The start date from property previous_ti_success.
+
+ :param state: If passed, it only take into account instances of a
specific state.
+ """
+ self.log.debug("previous_start_datewas called")
Review comment:
```suggestion
self.log.debug("previous_start_date was called")
```
----------------------------------------------------------------
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