github-actions[bot] commented on code in PR #40613:
URL: https://github.com/apache/beam/pull/40613#discussion_r4284150335
##########
sdks/python/apache_beam/utils/timestamp.py:
##########
@@ -166,7 +167,8 @@ def from_utc_datetime(cls, dt: datetime.datetime) ->
'Timestamp':
"dt has no timezone info " +
"(https://docs.python.org/3/library/datetime.html" +
"#aware-and-naive-objects): %s" % dt)
- if dt.tzinfo != pytz.utc and dt.tzinfo != datetime.timezone.utc:
+ if dt.tzinfo != pytz.utc and dt.tzinfo != datetime.timezone.utc and
dt.tzinfo != zoneinfo.ZoneInfo( # pylint: disable=line-too-long
+ "UTC"):
raise ValueError('dt not in UTC: %s' % dt)
Review Comment:
**🟡 Medium**: Whenever `dt.tzinfo` is neither `pytz.utc` nor
`datetime.timezone.utc` (for example, when a non-UTC `pytz` timezone is
passed), Python evaluates `zoneinfo.ZoneInfo("UTC")`. On platforms without
system IANA time zone data (such as Windows or minimal containers) where the
optional `tzdata` PyPI package is not installed (note `tzdata` is not in
`apache-beam`'s core `install_requires`), calling `zoneinfo.ZoneInfo("UTC")`
raises `zoneinfo.ZoneInfoNotFoundError` instead of `ValueError('dt not in UTC:
...')`.
Checking `not (isinstance(dt.tzinfo, zoneinfo.ZoneInfo) and dt.tzinfo.key ==
'UTC')` (or `getattr(dt.tzinfo, 'key', None) != 'UTC'`) avoids loading tzdata
on the fallback check, prevents `ZoneInfoNotFoundError` when `tzdata` is not
installed, and also works with `ZoneInfo.no_cache("UTC")` instances.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]