Repository navigation
Fix serialization of datetimes with a fixed UTC offset - #74922
Conversation
2a28470 to
b22fb93
Compare
fat-catTW
left a comment
There was a problem hiding this comment.
Thanks for the PR. Look good overall!
Non-blocking: could we also assert that the fixed offset itself survives the datetime round-trip?
test_datetime currently compares only timestamp(), so a value restored as 07:00+00:00 would still pass for an original 09:00+02:00.
An assertion such as the following would make the intended guarantee explicit:
assert deserialized_obj.utcoffset() == datetime.timedelta(hours=2)b22fb93 to
5511a30
Compare
Yep! Good call. The |
shahar1
left a comment
There was a problem hiding this comment.
Unnamed fixed-offset tzinfo (e.g. datetime.timezone(timedelta(hours=2))) now round-trips through serde as a pendulum FixedTimezone, matching how the existing UTC special case already worked, and the new parametrized case plus test_timezone_serialize_fixed_offset both fail on main without the fix. The extra utcoffset() assertion in test_datetime is a good catch too, since == on aware datetimes alone would not notice a lost offset.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.More on how Apache Airflow handles maintainer review:
Contributing guide.
Backport successfully created: v3-4-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
The serde timezone serializer can't handle timezones that are just a fixed offset with no name. The datetime serializer saves an empty place holder and reading the value back (e.g., via Xcom pull) fails. Take the following Dag:
On main,
do_somethingwould fail with:ValueError: ZoneInfo keys must be normalized relative paths, got:This PR adds support for timezones with a fixed, nonzero UTC offset and no name, by encoding them as a pendulum
FixedTimezone. Additional tests were added to cover the new behavior. TheNoNameTZhelper now returnsNonefrom utcoffset so thattest_timezone_serialize_no_namestill covers the fallback path (no name or fixed offset).Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.