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

zoneinfo.ZoneInfo AttributeError while parsing within the Django context #110

Open
mmulich opened this issue Aug 23, 2021 · 1 comment
Open

Comments

@mmulich
Copy link

mmulich commented Aug 23, 2021

I'm running into an error when using Delorean within a Django app context. This only happens when the Django app is loaded. For example, in the interpreter setup by django:

$ python manage.py shell
Python 3.9.6 (default, Jun 29 2021, 05:25:02) 
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> t = '2020-11-30T05:17:05.000000Z'
>>> import delorean
>>> delorean.parse(t).datetime

This results in:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File ".../lib/python3.9/site-packages/delorean/interface.py", line 87, in parse
    do = Delorean(dt, timezone=tz)
  File ".../lib/python3.9/site-packages/delorean/dates.py", line 202, in __init__
    self._dt = localize(datetime, self._tzinfo)
  File ".../lib/python3.9/site-packages/delorean/dates.py", line 157, in localize
    return tz.localize(dt)
AttributeError: 'zoneinfo.ZoneInfo' object has no attribute 'localize'

The same procedure done outside of django results in a successful parsing of the datetime.

$ python
Python 3.9.6 (default, Jun 29 2021, 05:25:02) 
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> t = '2020-11-30T05:17:05.000000Z'
>>> import delorean
>>> delorean.parse(t).datetime
datetime.datetime(2020, 11, 30, 5, 17, 5, tzinfo=<UTC>)

Note, it's the same environment, just not within the django shell setup.

AFAICT, the only difference is that Django is using a zoneinfo timezone instance, while pure python is finding any using a pytz timezone instance.

@wickeym
Copy link

wickeym commented Oct 8, 2021

There was an api change in tzinfo starting with version 3 it no longer returns a pytz object but rather a zoneinfo object. Delorean will either need to update to handle the new object or limit tzlocal to <= 2.1

I just ran into this issue. Friday afternoon is always a great time to debug issues 😄

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

No branches or pull requests

2 participants