llazzaro / django-scheduler

A calendaring app for Django.
BSD 3-Clause "New" or "Revised" License
1.27k stars 391 forks source link

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

Open Shavinder opened 2 years ago

Shavinder commented 2 years ago

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 commented 2 years ago

I'm also running into the same issue,

@Shavinder have you found a workaround?

Shavinder commented 2 years ago

I ve decided to use django swingtime. Its code is easier to understand. Plus it has a demo.

On Mon., Jan. 10, 2022, 6:33 a.m. Jeroen van der Laan < @.***> wrote:

I'm also running into the same issue,

@Shavinder https://github.com/Shavinder have you found a workaround?

— Reply to this email directly, view it on GitHub https://github.com/llazzaro/django-scheduler/issues/522#issuecomment-1008930926, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKYKTMY4LS27JIKRQWYFADUVLU43ANCNFSM5KYTIOBQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

raffael-mnhn commented 2 years ago

I have the same issue on python 3.8

raffael-mnhn commented 2 years ago

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

llazzaro commented 2 years ago

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

llazzaro commented 2 years ago

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

raffael-mnhn commented 2 years ago

@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 commented 2 years ago

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