ecerulm commented on a change in pull request #16631:
URL: https://github.com/apache/airflow/pull/16631#discussion_r658085739
##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -195,6 +196,19 @@ def serialize_to_json(
serialized_object[key] = value
return serialized_object
+ @classmethod
+ def serialize_timezone(cls, var: datetime.tzinfo) -> Any:
+ """Serializes a timezone to json"""
+ tz_name = getattr(var, 'name', None)
+ if not tz_name:
Review comment:
> It's a standard method that should always yield something useful
Well, not always with pendulum as explained in
https://github.com/apache/airflow/pull/16631#issuecomment-867612620 ,
`pendulum.timezone('Europe/Stockholm').tzname(...)` can return `CEST` which
**can't** be converted back with `pendulum.timezone('CEST')` as it raises
InvalidTimezone
I did try that at some point. The whole concept of `datetime.tzinfo` ->
`str` -> `datetime.tzinfo` works sometimes but there is no really hard
guarantee. So that's why I use the `.name` if present (which marginally
increases the chances of success serialization/deserialization)
--
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]