From c14a52e47801cfa8459c69b80b14a39e397b89e3 Mon Sep 17 00:00:00 2001 From: Jiajie Zhong Date: Mon, 22 Jul 2019 00:37:29 +0800 Subject: [PATCH] [AIRFLOW-5000] Remove duplicate end_date and reorder template * Remove the duplicate end_date in template context * Reorder template context key to make ds together --- airflow/models/taskinstance.py | 43 +++++++++++++++++----------------- tests/cli/test_cli.py | 2 +- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/airflow/models/taskinstance.py b/airflow/models/taskinstance.py index 5407c09b1d6b2..641b751fa2798 100644 --- a/airflow/models/taskinstance.py +++ b/airflow/models/taskinstance.py @@ -1198,46 +1198,45 @@ def __repr__(self): return str(self.var) return { + 'conf': configuration, 'dag': task.dag, + 'dag_run': dag_run, 'ds': ds, + 'ds_nodash': ds_nodash, + 'end_date': ds, + 'execution_date': self.execution_date, + 'inlets': task.inlets, + 'latest_date': ds, + 'macros': macros, 'next_ds': next_ds, 'next_ds_nodash': next_ds_nodash, + 'next_execution_date': next_execution_date, + 'outlets': task.outlets, + 'params': params, 'prev_ds': prev_ds, 'prev_ds_nodash': prev_ds_nodash, - 'ds_nodash': ds_nodash, - 'ts': ts, - 'ts_nodash': ts_nodash, - 'ts_nodash_with_tz': ts_nodash_with_tz, - 'yesterday_ds': yesterday_ds, - 'yesterday_ds_nodash': yesterday_ds_nodash, - 'tomorrow_ds': tomorrow_ds, - 'tomorrow_ds_nodash': tomorrow_ds_nodash, - 'END_DATE': ds, - 'end_date': ds, - 'dag_run': dag_run, - 'run_id': run_id, - 'execution_date': self.execution_date, 'prev_execution_date': prev_execution_date, 'prev_execution_date_success': lazy_object_proxy.Proxy( lambda: self.previous_execution_date_success), 'prev_start_date_success': lazy_object_proxy.Proxy(lambda: self.previous_start_date_success), - 'next_execution_date': next_execution_date, - 'latest_date': ds, - 'macros': macros, - 'params': params, + 'run_id': run_id, 'tables': tables, 'task': task, 'task_instance': self, - 'ti': self, 'task_instance_key_str': ti_key_str, - 'conf': configuration, 'test_mode': self.test_mode, + 'ti': self, + 'tomorrow_ds': tomorrow_ds, + 'tomorrow_ds_nodash': tomorrow_ds_nodash, + 'ts': ts, + 'ts_nodash': ts_nodash, + 'ts_nodash_with_tz': ts_nodash_with_tz, 'var': { + 'json': VariableJsonAccessor(), 'value': VariableAccessor(), - 'json': VariableJsonAccessor() }, - 'inlets': task.inlets, - 'outlets': task.outlets, + 'yesterday_ds': yesterday_ds, + 'yesterday_ds_nodash': yesterday_ds_nodash, } def overwrite_params_with_dag_run_conf(self, params, dag_run): diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py index a46212fd649ba..e2e2971ad7352 100644 --- a/tests/cli/test_cli.py +++ b/tests/cli/test_cli.py @@ -206,7 +206,7 @@ def test_test(self): output = out.getvalue() # Check that prints, and log messages, are shown - self.assertIn('END_DATE', output) + self.assertIn('end_date', output) self.assertIn("'example_python_operator__print_the_context__20180101'", output) finally: sys.stdout = saved_stdout