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

DateTimePGPSymmetricKeyField does not save with timezone info, is this a defect? #345

Closed
steezeburger opened this issue Apr 20, 2021 · 1 comment

Comments

@steezeburger
Copy link

steezeburger commented Apr 20, 2021

imagine some field:

expires_at = fields.DateTimePGPSymmetricKeyField(null=True)

set equal to:

from datetime import timedelta
from django.utils.timezone import now
...
expires_at = now() + timedelta(seconds=token['expires_in'])

I noticed there was an issue when I got the error:

can't compare offset-naive and offset-aware datetimes

from this call on my model:

@property
def is_expired(self):
    return self.expires_at < now()

Inspecting the unencrypted datetime next to a never encrypted datetime -- you can see the never encrypted datetime still has timezone information:
Screen Shot 2021-04-19 at 9 34 05 PM

I can remedy this by refacroting my is_expired method to:

import pytz
...
@property
def is_expired(self):
    return self.expires_at.replace(tzinfo=pytz.UTC) < now()

but I was curious if this was a defect.

Thanks for your time! :)

@peterfarrell
Copy link
Collaborator

This was fixed in #307 which is in master but not released on PyPi yet.

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

2 participants