You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by fo...@apache.org on 2018/05/02 20:49:58 UTC

incubator-airflow git commit: [AIRFLOW-2410][AIRFLOW-75] Set the timezone in the RBAC Web UI

Repository: incubator-airflow
Updated Branches:
  refs/heads/master 12ab796b1 -> 71954a52f


[AIRFLOW-2410][AIRFLOW-75] Set the timezone in the RBAC Web UI

SqlAlchemy does not know how to handle the
timestamp since it isnt
timezone aware

Closes #3303 from Fokko/AIRFLOW-2410


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/71954a52
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/71954a52
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/71954a52

Branch: refs/heads/master
Commit: 71954a52fc13accf1130d3d2a00263d7ec369b02
Parents: 12ab796
Author: Fokko Driesprong <fo...@godatadriven.com>
Authored: Wed May 2 22:49:39 2018 +0200
Committer: Fokko Driesprong <fo...@godatadriven.com>
Committed: Wed May 2 22:49:39 2018 +0200

----------------------------------------------------------------------
 airflow/utils/timezone.py | 19 +++++++++++++++++--
 airflow/www_rbac/views.py | 12 ++++++------
 2 files changed, 23 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/71954a52/airflow/utils/timezone.py
----------------------------------------------------------------------
diff --git a/airflow/utils/timezone.py b/airflow/utils/timezone.py
index af848df..6d49fbc 100644
--- a/airflow/utils/timezone.py
+++ b/airflow/utils/timezone.py
@@ -7,9 +7,9 @@
 # to you under the Apache License, Version 2.0 (the
 # "License"); you may not use this file except in compliance
 # with the License.  You may obtain a copy of the License at
-# 
+#
 #   http://www.apache.org/licenses/LICENSE-2.0
-# 
+#
 # Unless required by applicable law or agreed to in writing,
 # software distributed under the License is distributed on an
 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -64,6 +64,21 @@ def utcnow():
     return d
 
 
+def utc_epoch():
+    """
+    Gets the epoch in the users timezone
+    :return:
+    """
+
+    # pendulum utcnow() is not used as that sets a TimezoneInfo object
+    # instead of a Timezone. This is not pickable and also creates issues
+    # when using replace()
+    d = dt.datetime(1970, 1, 1)
+    d = d.replace(tzinfo=utc)
+
+    return d
+
+
 def convert_to_utc(value):
     """
     Returns the datetime with the default timezone added if timezone

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/71954a52/airflow/www_rbac/views.py
----------------------------------------------------------------------
diff --git a/airflow/www_rbac/views.py b/airflow/www_rbac/views.py
index 9636a58..7c20a65 100644
--- a/airflow/www_rbac/views.py
+++ b/airflow/www_rbac/views.py
@@ -7,9 +7,9 @@
 # to you under the Apache License, Version 2.0 (the
 # "License"); you may not use this file except in compliance
 # with the License.  You may obtain a copy of the License at
-# 
+#
 #   http://www.apache.org/licenses/LICENSE-2.0
-# 
+#
 # Unless required by applicable law or agreed to in writing,
 # software distributed under the License is distributed on an
 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -880,7 +880,7 @@ class Airflow(AirflowBaseView):
             base_date = dag.latest_execution_date or timezone.utcnow()
 
         dates = dag.date_range(base_date, num=-abs(num_runs))
-        min_date = dates[0] if dates else datetime(2000, 1, 1)
+        min_date = dates[0] if dates else timezone.utc_epoch()
 
         DR = models.DagRun
         dag_runs = (
@@ -1113,7 +1113,7 @@ class Airflow(AirflowBaseView):
             base_date = dag.latest_execution_date or timezone.utcnow()
 
         dates = dag.date_range(base_date, num=-abs(num_runs))
-        min_date = dates[0] if dates else datetime(2000, 1, 1)
+        min_date = dates[0] if dates else timezone.utc_epoch()
 
         root = request.args.get('root')
         if root:
@@ -1216,7 +1216,7 @@ class Airflow(AirflowBaseView):
             base_date = dag.latest_execution_date or timezone.utcnow()
 
         dates = dag.date_range(base_date, num=-abs(num_runs))
-        min_date = dates[0] if dates else datetime(2000, 1, 1)
+        min_date = dates[0] if dates else timezone.utc_epoch()
 
         root = request.args.get('root')
         if root:
@@ -1279,7 +1279,7 @@ class Airflow(AirflowBaseView):
             base_date = dag.latest_execution_date or timezone.utcnow()
 
         dates = dag.date_range(base_date, num=-abs(num_runs))
-        min_date = dates[0] if dates else datetime(2000, 1, 1)
+        min_date = dates[0] if dates else timezone.utc_epoch()
 
         root = request.args.get('root')
         if root: