Repository: incubator-airflow Updated Branches: refs/heads/v1-10-test 9184ebcb5 -> a05a72eee
[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 (cherry picked from commit 71954a52fc13accf1130d3d2a00263d7ec369b02) Signed-off-by: Fokko Driesprong <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/a05a72ee Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/a05a72ee Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/a05a72ee Branch: refs/heads/v1-10-test Commit: a05a72eeefc374acde40bf3ec59630c11d06f957 Parents: 9184ebc Author: Fokko Driesprong <[email protected]> Authored: Wed May 2 22:49:39 2018 +0200 Committer: Fokko Driesprong <[email protected]> Committed: Wed May 2 22:50:09 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/a05a72ee/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/a05a72ee/airflow/www_rbac/views.py ---------------------------------------------------------------------- diff --git a/airflow/www_rbac/views.py b/airflow/www_rbac/views.py index f064c14..5857c0d 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 = ( @@ -1109,7 +1109,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: @@ -1212,7 +1212,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: @@ -1275,7 +1275,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:
