38
38
import jinja2
39
39
import lazy_object_proxy
40
40
import pendulum
41
- from deprecated import deprecated
42
41
from jinja2 import TemplateAssertionError , UndefinedError
43
42
from sqlalchemy import (
44
43
Column ,
80
79
AirflowSkipException ,
81
80
AirflowTaskTerminated ,
82
81
AirflowTaskTimeout ,
83
- DagRunNotFound ,
84
82
RemovedInAirflow3Warning ,
85
83
TaskDeferralError ,
86
84
TaskDeferred ,
@@ -425,7 +423,6 @@ def _stop_remaining_tasks(*, task_instance: TaskInstance | TaskInstancePydantic,
425
423
def clear_task_instances (
426
424
tis : list [TaskInstance ],
427
425
session : Session ,
428
- activate_dag_runs : None = None ,
429
426
dag : DAG | None = None ,
430
427
dag_run_state : DagRunState | Literal [False ] = DagRunState .QUEUED ,
431
428
) -> None :
@@ -443,7 +440,6 @@ def clear_task_instances(
443
440
:param dag_run_state: state to set finished DagRuns to.
444
441
If set to False, DagRuns state will not be changed.
445
442
:param dag: DAG object
446
- :param activate_dag_runs: Deprecated parameter, do not pass
447
443
"""
448
444
job_ids = []
449
445
# Keys: dag_id -> run_id -> map_indexes -> try_numbers -> task_id
@@ -521,16 +517,6 @@ def clear_task_instances(
521
517
522
518
session .execute (update (Job ).where (Job .id .in_ (job_ids )).values (state = JobState .RESTARTING ))
523
519
524
- if activate_dag_runs is not None :
525
- warnings .warn (
526
- "`activate_dag_runs` parameter to clear_task_instances function is deprecated. "
527
- "Please use `dag_run_state`" ,
528
- RemovedInAirflow3Warning ,
529
- stacklevel = 2 ,
530
- )
531
- if not activate_dag_runs :
532
- dag_run_state = False
533
-
534
520
if dag_run_state is not False and tis :
535
521
from airflow .models .dagrun import DagRun # Avoid circular import
536
522
@@ -1922,7 +1908,6 @@ class TaskInstance(Base, LoggingMixin):
1922
1908
def __init__ (
1923
1909
self ,
1924
1910
task : Operator ,
1925
- execution_date : datetime | None = None ,
1926
1911
run_id : str | None = None ,
1927
1912
state : str | None = None ,
1928
1913
map_index : int = - 1 ,
@@ -1938,42 +1923,7 @@ def __init__(
1938
1923
# init_on_load will config the log
1939
1924
self .init_on_load ()
1940
1925
1941
- if run_id is None and execution_date is not None :
1942
- from airflow .models .dagrun import DagRun # Avoid circular import
1943
-
1944
- warnings .warn (
1945
- "Passing an execution_date to `TaskInstance()` is deprecated in favour of passing a run_id" ,
1946
- RemovedInAirflow3Warning ,
1947
- # Stack level is 4 because SQLA adds some wrappers around the constructor
1948
- stacklevel = 4 ,
1949
- )
1950
- # make sure we have a localized execution_date stored in UTC
1951
- if execution_date and not timezone .is_localized (execution_date ):
1952
- self .log .warning (
1953
- "execution date %s has no timezone information. Using default from dag or system" ,
1954
- execution_date ,
1955
- )
1956
- if self .task .has_dag ():
1957
- if TYPE_CHECKING :
1958
- assert self .task .dag
1959
- execution_date = timezone .make_aware (execution_date , self .task .dag .timezone )
1960
- else :
1961
- execution_date = timezone .make_aware (execution_date )
1962
-
1963
- execution_date = timezone .convert_to_utc (execution_date )
1964
- with create_session () as session :
1965
- run_id = (
1966
- session .query (DagRun .run_id )
1967
- .filter_by (dag_id = self .dag_id , execution_date = execution_date )
1968
- .scalar ()
1969
- )
1970
- if run_id is None :
1971
- raise DagRunNotFound (
1972
- f"DagRun for { self .dag_id !r} with date { execution_date } not found"
1973
- ) from None
1974
-
1975
1926
self .run_id = run_id
1976
-
1977
1927
self .try_number = 0
1978
1928
self .max_tries = self .task .retries
1979
1929
self .unixname = getuser ()
@@ -1989,26 +1939,6 @@ def __init__(
1989
1939
def __hash__ (self ):
1990
1940
return hash ((self .task_id , self .dag_id , self .run_id , self .map_index ))
1991
1941
1992
- @property
1993
- @deprecated (reason = "Use try_number instead." , version = "2.10.0" , category = RemovedInAirflow3Warning )
1994
- def _try_number (self ):
1995
- """
1996
- Do not use. For semblance of backcompat.
1997
-
1998
- :meta private:
1999
- """
2000
- return self .try_number
2001
-
2002
- @_try_number .setter
2003
- @deprecated (reason = "Use try_number instead." , version = "2.10.0" , category = RemovedInAirflow3Warning )
2004
- def _try_number (self , val ):
2005
- """
2006
- Do not use. For semblance of backcompat.
2007
-
2008
- :meta private:
2009
- """
2010
- self .try_number = val
2011
-
2012
1942
@property
2013
1943
def stats_tags (self ) -> dict [str , str ]:
2014
1944
"""Returns task instance tags."""
@@ -2051,23 +1981,6 @@ def init_on_load(self) -> None:
2051
1981
"""Initialize the attributes that aren't stored in the DB."""
2052
1982
self .test_mode = False # can be changed when calling 'run'
2053
1983
2054
- @property
2055
- @deprecated (reason = "Use try_number instead." , version = "2.10.0" , category = RemovedInAirflow3Warning )
2056
- def prev_attempted_tries (self ) -> int :
2057
- """
2058
- Calculate the total number of attempted tries, defaulting to 0.
2059
-
2060
- This used to be necessary because try_number did not always tell the truth.
2061
-
2062
- :meta private:
2063
- """
2064
- return self .try_number
2065
-
2066
- @property
2067
- def next_try_number (self ) -> int :
2068
- # todo (dstandish): deprecate this property; we don't need a property that is just + 1
2069
- return self .try_number + 1
2070
-
2071
1984
@property
2072
1985
def operator_name (self ) -> str | None :
2073
1986
"""@property: use a more friendly display name for the operator, if set."""
@@ -2498,40 +2411,6 @@ def get_previous_ti(
2498
2411
"""
2499
2412
return _get_previous_ti (task_instance = self , state = state , session = session )
2500
2413
2501
- @property
2502
- def previous_ti (self ) -> TaskInstance | TaskInstancePydantic | None :
2503
- """
2504
- This attribute is deprecated.
2505
-
2506
- Please use :class:`airflow.models.taskinstance.TaskInstance.get_previous_ti`.
2507
- """
2508
- warnings .warn (
2509
- """
2510
- This attribute is deprecated.
2511
- Please use `airflow.models.taskinstance.TaskInstance.get_previous_ti` method.
2512
- """ ,
2513
- RemovedInAirflow3Warning ,
2514
- stacklevel = 2 ,
2515
- )
2516
- return self .get_previous_ti ()
2517
-
2518
- @property
2519
- def previous_ti_success (self ) -> TaskInstance | TaskInstancePydantic | None :
2520
- """
2521
- This attribute is deprecated.
2522
-
2523
- Please use :class:`airflow.models.taskinstance.TaskInstance.get_previous_ti`.
2524
- """
2525
- warnings .warn (
2526
- """
2527
- This attribute is deprecated.
2528
- Please use `airflow.models.taskinstance.TaskInstance.get_previous_ti` method.
2529
- """ ,
2530
- RemovedInAirflow3Warning ,
2531
- stacklevel = 2 ,
2532
- )
2533
- return self .get_previous_ti (state = DagRunState .SUCCESS )
2534
-
2535
2414
@provide_session
2536
2415
def get_previous_execution_date (
2537
2416
self ,
@@ -2558,23 +2437,6 @@ def get_previous_start_date(
2558
2437
"""
2559
2438
return _get_previous_start_date (task_instance = self , state = state , session = session )
2560
2439
2561
- @property
2562
- def previous_start_date_success (self ) -> pendulum .DateTime | None :
2563
- """
2564
- This attribute is deprecated.
2565
-
2566
- Please use :class:`airflow.models.taskinstance.TaskInstance.get_previous_start_date`.
2567
- """
2568
- warnings .warn (
2569
- """
2570
- This attribute is deprecated.
2571
- Please use `airflow.models.taskinstance.TaskInstance.get_previous_start_date` method.
2572
- """ ,
2573
- RemovedInAirflow3Warning ,
2574
- stacklevel = 2 ,
2575
- )
2576
- return self .get_previous_start_date (state = DagRunState .SUCCESS )
2577
-
2578
2440
@provide_session
2579
2441
def are_dependencies_met (
2580
2442
self , dep_context : DepContext | None = None , session : Session = NEW_SESSION , verbose : bool = False
@@ -4115,21 +3977,6 @@ def __eq__(self, other):
4115
3977
return self .__dict__ == other .__dict__
4116
3978
return NotImplemented
4117
3979
4118
- def as_dict (self ):
4119
- warnings .warn (
4120
- "This method is deprecated. Use BaseSerialization.serialize." ,
4121
- RemovedInAirflow3Warning ,
4122
- stacklevel = 2 ,
4123
- )
4124
- new_dict = dict (self .__dict__ )
4125
- for key in new_dict :
4126
- if key in ["start_date" , "end_date" ]:
4127
- val = new_dict [key ]
4128
- if not val or isinstance (val , str ):
4129
- continue
4130
- new_dict .update ({key : val .isoformat ()})
4131
- return new_dict
4132
-
4133
3980
@classmethod
4134
3981
def from_ti (cls , ti : TaskInstance ) -> SimpleTaskInstance :
4135
3982
return cls (
@@ -4150,24 +3997,6 @@ def from_ti(cls, ti: TaskInstance) -> SimpleTaskInstance:
4150
3997
priority_weight = ti .priority_weight if hasattr (ti , "priority_weight" ) else None ,
4151
3998
)
4152
3999
4153
- @classmethod
4154
- def from_dict (cls , obj_dict : dict ) -> SimpleTaskInstance :
4155
- warnings .warn (
4156
- "This method is deprecated. Use BaseSerialization.deserialize." ,
4157
- RemovedInAirflow3Warning ,
4158
- stacklevel = 2 ,
4159
- )
4160
- ti_key = TaskInstanceKey (* obj_dict .pop ("key" ))
4161
- start_date = None
4162
- end_date = None
4163
- start_date_str : str | None = obj_dict .pop ("start_date" )
4164
- end_date_str : str | None = obj_dict .pop ("end_date" )
4165
- if start_date_str :
4166
- start_date = timezone .parse (start_date_str )
4167
- if end_date_str :
4168
- end_date = timezone .parse (end_date_str )
4169
- return cls (** obj_dict , start_date = start_date , end_date = end_date , key = ti_key )
4170
-
4171
4000
4172
4001
class TaskInstanceNote (TaskInstanceDependencies ):
4173
4002
"""For storage of arbitrary notes concerning the task instance."""
0 commit comments