toastdriven/django-tastypie — pull request #561 by tunix (2012-07-12 14:10:14+00:00)
Title: ValueError: astimezone() cannot be applied to a naive datetime

Hey There,

I get the following error when I try to add new ApiKey via django-admin. I'm currently using the latest django-git and tastypie-git versions:

Traceback (most recent call last):

File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 113, in get_response
response = callback(request, *callback_args, **callback_kwargs)

File "/usr/lib/python2.7/site-packages/django/contrib/admin/options.py", line 366, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)

File "/usr/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
response = view_func(request, *args, **kwargs)

File "/usr/lib/python2.7/site-packages/django/views/decorators/cache.py", line 89, in _wrapped_view_func
response = view_func(request, *args, **kwargs)

File "/usr/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 196, in inner
return view(request, *args, **kwargs)

File "/usr/lib/python2.7/site-packages/django/utils/decorators.py", line 25, in _wrapper
return bound_func(*args, **kwargs)

File "/usr/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
response = view_func(request, *args, **kwargs)

File "/usr/lib/python2.7/site-packages/django/utils/decorators.py", line 21, in bound_func
return func(self, *args2, **kwargs2)

File "/usr/lib/python2.7/site-packages/django/db/transaction.py", line 208, in inner
return func(*args, **kwargs)

File "/usr/lib/python2.7/site-packages/django/contrib/admin/options.py", line 970, in add_view
form = ModelForm(initial=initial)

File "/usr/lib/python2.7/site-packages/django/forms/models.py", line 234, in init
self.instance = opts.model()

File "/usr/lib/python2.7/site-packages/django/db/models/base.py", line 353, in init
val = field.get_default()

File "/usr/lib/python2.7/site-packages/django/db/models/fields/init.py", line 386, in get_default
return self.default()

File "/usr/lib/python2.7/site-packages/tastypie/utils/timezone.py", line 20, in now
return timezone.localtime(timezone.now())

File "/usr/lib/python2.7/site-packages/django/utils/timezone.py", line 235, in localtime
value = value.astimezone(timezone)

ValueError: astimezone() cannot be applied to a naive datetime
Seems like in utils/timezone.py you try to get timezone aware time from a naive datetime object which causes the error.