2727from datetime import datetime , timedelta
2828from functools import partial
2929from tempfile import NamedTemporaryFile
30- from typing import IO , TYPE_CHECKING , Any , Dict , Iterable , List , NamedTuple , Optional , Tuple , Union
30+ from typing import IO , TYPE_CHECKING , Any , Callable , Dict , Iterable , List , NamedTuple , Optional , Tuple , Union
3131from urllib .parse import quote
3232
3333import dill
@@ -1786,17 +1786,16 @@ def get_template_context(self, session: Session = None, ignore_param_exceptions:
17861786 if conf .getboolean ('core' , 'dag_run_conf_overrides_params' ):
17871787 self .overwrite_params_with_dag_run_conf (params = params , dag_run = dag_run )
17881788
1789- interval_start = dag .get_run_data_interval (dag_run ).start
1790- ds = interval_start .strftime ('%Y-%m-%d' )
1789+ logical_date = timezone .coerce_datetime (self .execution_date )
1790+ ds = logical_date .strftime ('%Y-%m-%d' )
1791+ ds_nodash = ds .replace ('-' , '' )
1792+ ts = logical_date .isoformat ()
1793+ ts_nodash = logical_date .strftime ('%Y%m%dT%H%M%S' )
1794+ ts_nodash_with_tz = ts .replace ('-' , '' ).replace (':' , '' )
17911795
17921796 # Now validates Params and convert them into a simple dict
17931797 task .params = params .validate ()
17941798
1795- ds_nodash = ds .replace ('-' , '' )
1796- ts = interval_start .isoformat ()
1797- ts_nodash = interval_start .strftime ('%Y%m%dT%H%M%S' )
1798- ts_nodash_with_tz = ts .replace ('-' , '' ).replace (':' , '' )
1799-
18001799 @cache # Prevent multiple database access.
18011800 def _get_previous_dagrun_success () -> Optional ["DagRun" ]:
18021801 return self .get_previous_dagrun (state = State .SUCCESS , session = session )
@@ -1908,14 +1907,23 @@ def get(
19081907
19091908 # Create lazy proxies for deprecated stuff.
19101909
1911- def deprecated_proxy (func , * , key , replacement = None ) -> lazy_object_proxy .Proxy :
1910+ def deprecated_proxy (
1911+ func : Callable [[], Any ],
1912+ * ,
1913+ key : str ,
1914+ replacements : Optional [List [str ]] = None ,
1915+ ) -> lazy_object_proxy .Proxy :
19121916 def deprecated_func ():
19131917 message = (
19141918 f"Accessing { key !r} from the template is deprecated and "
19151919 f"will be removed in a future version."
19161920 )
1917- if replacement :
1918- message += f" Please use { replacement !r} instead."
1921+ if replacements :
1922+ display_except_last = ", " .join (repr (r ) for r in replacements [:- 1 ])
1923+ if display_except_last :
1924+ message += f" Please use { display_except_last } or { replacements [- 1 ]!r} instead."
1925+ else :
1926+ message += f" Please use { replacements [- 1 ]!r} instead."
19191927 warnings .warn (message , DeprecationWarning )
19201928 return func ()
19211929
@@ -1993,22 +2001,23 @@ def get_prev_ds_nodash() -> Optional[str]:
19932001 'ds' : ds ,
19942002 'ds_nodash' : ds_nodash ,
19952003 'execution_date' : deprecated_proxy (
1996- lambda : timezone . coerce_datetime ( self . execution_date ) ,
2004+ lambda : logical_date ,
19972005 key = 'execution_date' ,
1998- replacement = ' data_interval_start' ,
2006+ replacements = [ 'logical_date' , ' data_interval_start'] ,
19992007 ),
20002008 'inlets' : task .inlets ,
2009+ 'logical_date' : logical_date ,
20012010 'macros' : macros ,
2002- 'next_ds' : deprecated_proxy (get_next_ds , key = "next_ds" , replacement = "data_interval_end | ds" ),
2011+ 'next_ds' : deprecated_proxy (get_next_ds , key = "next_ds" , replacements = [ "data_interval_end | ds" ] ),
20032012 'next_ds_nodash' : deprecated_proxy (
20042013 get_next_ds_nodash ,
20052014 key = "next_ds_nodash" ,
2006- replacement = "data_interval_end | ds_nodash" ,
2015+ replacements = [ "data_interval_end | ds_nodash" ] ,
20072016 ),
20082017 'next_execution_date' : deprecated_proxy (
20092018 get_next_execution_date ,
20102019 key = 'next_execution_date' ,
2011- replacement = 'data_interval_end' ,
2020+ replacements = [ 'data_interval_end' ] ,
20122021 ),
20132022 'outlets' : task .outlets ,
20142023 'params' : task .params ,
@@ -2020,7 +2029,7 @@ def get_prev_ds_nodash() -> Optional[str]:
20202029 'prev_execution_date_success' : deprecated_proxy (
20212030 lambda : self .get_previous_execution_date (state = State .SUCCESS , session = session ),
20222031 key = 'prev_execution_date_success' ,
2023- replacement = 'prev_data_interval_start_success' ,
2032+ replacements = [ 'prev_data_interval_start_success' ] ,
20242033 ),
20252034 'prev_start_date_success' : lazy_object_proxy .Proxy (get_prev_start_date_success ),
20262035 'run_id' : self .run_id ,
0 commit comments