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

'backports.zoneinfo.ZoneInfo' object has no attribute 'localize' #522

Open
Shavinder opened this issue Dec 26, 2021 · 8 comments
Open

'backports.zoneinfo.ZoneInfo' object has no attribute 'localize' #522

Shavinder opened this issue Dec 26, 2021 · 8 comments

Comments

@Shavinder
Copy link

Shavinder commented Dec 26, 2021

Here is my traceback:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/schedule/calendar/tri_month/example/

Django Version: 4.0
Python Version: 3.8.2
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.admin',
'debug_toolbar',
'djangobower',
'schedule',
'project_sample')
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware']

Traceback (most recent call last):
File "C:\Users\sh\source\repos\django-scheduler-sample-master\venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\sh\source\repos\django-scheduler-sample-master\venv\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\sh\source\repos\django-scheduler-sample-master\venv\lib\site-packages\schedule\utils.py", line 221, in decorator
return function(request, *args, **kwargs)
File "C:\Users\sh\source\repos\django-scheduler-sample-master\venv\lib\site-packages\django\views\generic\base.py", line 69, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\sh\source\repos\django-scheduler-sample-master\venv\lib\site-packages\django\views\generic\base.py", line 101, in dispatch
return handler(request, *args, **kwargs)
File "C:\Users\sh\source\repos\django-scheduler-sample-master\venv\lib\site-packages\django\views\generic\detail.py", line 107, in get
context = self.get_context_data(object=self.object)
File "C:\Users\sh\source\repos\django-scheduler-sample-master\venv\lib\site-packages\schedule\views.py", line 124, in get_context_data
period = period_class(event_list, date, tzinfo=local_timezone)
File "C:\Users\sh\source\repos\django-scheduler-sample-master\venv\lib\site-packages\schedule\periods.py", line 259, in init
start, end = self._get_month_range(date)
File "C:\Users\sh\source\repos\django-scheduler-sample-master\venv\lib\site-packages\schedule\periods.py", line 322, in _get_month_range
local_start = self.tzinfo.localize(naive_start)

Exception Type: AttributeError at /schedule/calendar/tri_month/example/
Exception Value: 'backports.zoneinfo.ZoneInfo' object has no attribute 'localize'

@alterlai
Copy link

I'm also running into the same issue,

@Shavinder have you found a workaround?

@Shavinder
Copy link
Author

Shavinder commented Jan 10, 2022 via email

@raffael-mnhn
Copy link

I have the same issue on python 3.8

@raffael-mnhn
Copy link

This is related to changes in python 3.8. It can be mitigated using:
USE_DEPRECATED_PYTZ = True in your settings.

@llazzaro
Copy link
Owner

@raffael-mnhn thanks for the suggestion. I'm working on a fix, however, the current fix has some DST regressions.

@llazzaro
Copy link
Owner

Please check branch: 522-fix-backports-zoneinfo-ZoneInfo

@raffael-mnhn
Copy link

@llazzaro I just tried this out by removing django-scheduler from my requirements.txt and substituting it with git+https://github.com/llazzaro/django-scheduler.git@522-fix-backports-zoneinfo-ZoneInfo#egg=django-scheduler followed by pip install -r requirements.txt. Then I removed the USE_DEPRECATED_PYTZ = True from settings.py and ran the application. It starts up as it should and generally seems to have no problems.

Thanks for the fix!

@llazzaro
Copy link
Owner

llazzaro commented Apr 5, 2022

Good to hear!
I think USE_DEPRECATED_PYTZ = True is not required with the fix.
I will try to publish on pipy

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

4 participants