Skip to content

Loading…

astimezone() cannot be applied to a naive datetime #233

Closed
coderam opened this Issue · 6 comments

3 participants

@coderam

I upgraded to the latest blog zinnia and to Django 1.5.1 from 1.4.x and receive the following error:

astimezone() cannot be applied to a naive datetime

Copy and pasted:

Environment:

Request Method: GET
Request URL: http://givity.coml:8000/blog/

Django Version: 1.5.1
Python Version: 2.7.4
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'tagging',
'mptt',
'zinnia',
'django_extensions',
'django.contrib.formtools',
'sorl.thumbnail',
'base',
'accounts')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'base.middleware.subdomain.SubdomainMiddleware')

Traceback:
File "C:\Users\coderam\Envs\givity\lib\site-packages\django\core\handlers\base.py" in get_response

  1. response = callback(request, callback_args, *callback_kwargs) File "C:\Users\coderam\Envs\givity\lib\site-packages\django\views\generic\base.py" in view
  2. return self.dispatch(request, args, *kwargs) File "C:\Users\coderam\Envs\givity\lib\site-packages\django\views\generic\base.py" in dispatch
  3. return handler(request, args, *kwargs) File "C:\Users\coderam\Envs\givity\lib\site-packages\django\views\generic\dates.py" in get
  4. return self.render_to_response(context) File "C:\Users\coderam\Envs\givity\lib\site-packages\django\views\generic\base.py" in render_to_response
  5. template = self.get_template_names(), File "C:\Users\coderam\Envs\givity\lib\site-packages\zinnia\views\mixins\templates.py" in get_template_names
  6. year = self.get_archive_part_value('year') File "C:\Users\coderam\Envs\givity\lib\site-packages\zinnia\views\mixins\templates.py" in get_archive_part_value
  7. self.today = timezone.localtime(timezone.now()).date() File "C:\Users\coderam\Envs\givity\lib\site-packages\django\utils\timezone.py" in localtime
  8. value = value.astimezone(timezone)

Exception Type: ValueError at /blog/
Exception Value: astimezone() cannot be applied to a naive datetime

@gin

I just installed zinnia and I received the same error after access to the /blog and when I try to add a new entry

env:
Python 2.6
Django 1.5.0
Zinnia 0.12.3

@gin

I was investigating how to fix that cloning zinnia, and I see django.utils.timezone.now() convert that object datetime but it depends if settings.USE_TZ is enabled so I did then I fixed that.

settings.py

USE_TZ = True

That fixed it!.

@coderam
@gin

@coderam I didn't any change in Zinnia code, just enable USE_TZ in your settings

@Fantomas42
Owner

Hi,

thank you for the bug report, I confirm the issue,
some tests need to be done when USE_TZ is set to False.

Regards

@Fantomas42
Owner

Note this bug is related to Django 1.5.x only

@jrutila jrutila pushed a commit to jrutila/django-blog-zinnia that referenced this issue
@Fantomas42 Fix Entry.get_absolute_url when USE_TZ is set to False #233
Conflicts:
	zinnia/models_bases/entry.py
	zinnia/tests/__init__.py
39949d4
@jrutila jrutila pushed a commit to jrutila/django-blog-zinnia that referenced this issue
@Fantomas42 Fix breadcrumbs for Entry detail page with naive datetime #233 df53b9c
@jrutila jrutila pushed a commit to jrutila/django-blog-zinnia that referenced this issue
@Fantomas42 Fix EntryToday view when USE_TZ is set to False #233 11eb1b6
@jrutila jrutila pushed a commit to jrutila/django-blog-zinnia that referenced this issue
@Fantomas42 Complete the tests of view with USE_TZ alternatively set to True and …
…False, closes #233

Conflicts:
	zinnia/tests/views.py
db1fa98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.