bread-and-pepper/django-userena — Issue #151: can't compare offset-naive and offset-aware datetimes
Author: intellisense
Created: 2012-01-25 21:51:35+00:00
State: open

This is the possible bug in

userena/models.py in activation_key_expired, line 169

When django application has enabled timezone information then

datetime.datetime.now() >= expiration_date

comparison produces above error as datetime.datetime.now() is naive (does not have timezone info) while expiration_date is aware (have timezone info). Either you make datetime.datetime.now() timezone aware before comparison or removing the timezone info (see code below) from expiration_date do the trick.

def activation_key_expired(self):
"""
Checks if activation key is expired.

Returns ``True`` when the ``activation_key`` of the user is expired and
``False`` if the key is still valid.

The key is expired when it's set to the value defined in
``USERENA_ACTIVATED`` or ``activation_key_created`` is beyond the
amount of days defined in ``USERENA_ACTIVATION_DAYS``.

"""
expiration_days = datetime.timedelta(days=userena_settings.USERENA_ACTIVATION_DAYS)
dt = self.user.date_joined.replace(tzinfo=None)
expiration_date = dt + expiration_days
if self.activation_key == userena_settings.USERENA_ACTIVATED:
return True
if datetime.datetime.now() >= expiration_date:
return True
return False