Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the "Factory" timezone on systems that use the system zoneinfo database can cause problems #114

Closed
knobix opened this issue Oct 3, 2023 · 1 comment · Fixed by #115

Comments

@knobix
Copy link
Contributor

knobix commented Oct 3, 2023

On some systems, e.g. FreeBSD, if the system installied zoneinfo database is used this can lead to ValueError exceptions if using the Factory timezone.

The affected line is: https://github.com/mfogel/django-timezone-field/blob/main/timezone_field/backends/zoneinfo.py#L21

Here's a way to reproduce the issue:

import zoneinfo

print("Current TZPATH: {}".format(zoneinfo.TZPATH))
try:
    print("ZoneInfo: {}".format(zoneinfo.ZoneInfo('Factory')))
except Exception as error:
    print("An error occurred: {}".format(error))
    pass

Output:

Current TZPATH: ('/usr/share/zoneinfo', '/usr/lib/zoneinfo', '/usr/share/lib/zoneinfo', '/etc/zoneinfo')
An error occurred: Invalid STD format in b'<Local time zone must be set--use tzsetup>0'`

If using the tzdata package the problem doesn't occur:

import zoneinfo

zoneinfo.reset_tzpath(["/usr/local/lib/python3.9/site-packages/tzdata/zoneinfo/"])
print("Current TZPATH: {}".format(zoneinfo.TZPATH))
print("ZoneInfo: {}".format(zoneinfo.ZoneInfo('Factory')))

Output:

Current TZPATH: ('/usr/local/lib/python3.9/site-packages/tzdata/zoneinfo/',)
ZoneInfo: Factory

The described behavior was observed on FreeBSD 12.4-RELEASE, 13.2-RELEASE and 14.0-BETA4 with Python 3.9.18.

@mfogel
Copy link
Owner

mfogel commented Oct 4, 2023

Thanks for the bug report and fix @knobix ! Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants