You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2018/08/09 02:13:10 UTC

[GitHub] lxneng closed pull request #3554: [AIRFLOW-2686] Fix Default Variables not base on default_timezone

lxneng closed pull request #3554: [AIRFLOW-2686] Fix Default Variables not base on default_timezone
URL: https://github.com/apache/incubator-airflow/pull/3554
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/models.py b/airflow/models.py
index 260c0ba5a2..2fe229a685 100755
--- a/airflow/models.py
+++ b/airflow/models.py
@@ -1809,14 +1809,15 @@ def get_template_context(self, session=None):
         tables = None
         if 'tables' in task.params:
             tables = task.params['tables']
+        # convert to default timezone
+        execution_date_tz = settings.TIMEZONE.convert(self.execution_date)
+        ds = execution_date_tz.strftime('%Y-%m-%d')
+        ts = execution_date_tz.isoformat()
+        yesterday_ds = (execution_date_tz - timedelta(1)).strftime('%Y-%m-%d')
+        tomorrow_ds = (execution_date_tz + timedelta(1)).strftime('%Y-%m-%d')
 
-        ds = self.execution_date.strftime('%Y-%m-%d')
-        ts = self.execution_date.isoformat()
-        yesterday_ds = (self.execution_date - timedelta(1)).strftime('%Y-%m-%d')
-        tomorrow_ds = (self.execution_date + timedelta(1)).strftime('%Y-%m-%d')
-
-        prev_execution_date = task.dag.previous_schedule(self.execution_date)
-        next_execution_date = task.dag.following_schedule(self.execution_date)
+        prev_execution_date = task.dag.previous_schedule(execution_date_tz)
+        next_execution_date = task.dag.following_schedule(execution_date_tz)
 
         next_ds = None
         if next_execution_date:
@@ -1903,7 +1904,7 @@ def __repr__(self):
             'end_date': ds,
             'dag_run': dag_run,
             'run_id': run_id,
-            'execution_date': self.execution_date,
+            'execution_date': execution_date_tz,
             'prev_execution_date': prev_execution_date,
             'next_execution_date': next_execution_date,
             'latest_date': ds,


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services