dstandish commented on a change in pull request #5332: [AIRFLOW-3391] Upgrade
pendulum to latest major version.
URL: https://github.com/apache/airflow/pull/5332#discussion_r294097557
##########
File path: airflow/utils/timezone.py
##########
@@ -89,10 +89,11 @@ def convert_to_utc(value):
if not value:
return value
- if not is_localized(value):
- value = pendulum.instance(value, TIMEZONE)
-
- return value.astimezone(utc)
+ return (
Review comment:
The issue causing failing `test_following_previous_schedule` is due to this
`convert_to_utc` function.
The problem is with using `pendulum.instance()` in the localized case.
To see why, you can run this:
```
local_tz = pendulum.timezone('Europe/Zurich')
start = local_tz.convert(datetime.datetime(2018, 10, 28, 2, 55),
dst_rule=pendulum.PRE_TRANSITION)
print(start.isoformat()) # '2018-10-28T02:55:00+02:00'
print(pendulum.instance(start).isoformat()) # '2018-10-28T02:55:00+01:00'
```
Replacing your return statement with the following seems to resolve the
issue:
```suggestion
if not is_localized(value):
value = pendulum.instance(value, TIMEZONE)
return utc.convert(value)
```
I also noticed that if you revert entirely the change to `convert_to_utc` in
this file, the tests pass so I am not if this change is necessary at all. But
in any case I'll note that `utc.convert(value)` is a method of
`pendulum.tz.Timezone`, whereas `value.astimezone(utc)` is `datetime`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services