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

Timezone and get_datetaken #17

Open
KosuzuMotoori opened this issue Dec 20, 2020 · 1 comment
Open

Timezone and get_datetaken #17

KosuzuMotoori opened this issue Dec 20, 2020 · 1 comment
Labels
bug Something isn't working docs help wanted Extra attention is needed

Comments

@KosuzuMotoori
Copy link

If timezone support is enabled in django, get_datetaken gives RuntimeWarning:

"DateTimeField Photo.taken received a naive datetime (2020-12-12 11:50:20) while time zone support is active."
And saves wrong datetime in to database.

How can I fix it?

denormalized_fields={'taken': get_datetaken}

@escaped escaped added bug Something isn't working help wanted Extra attention is needed docs labels Jan 11, 2021
@escaped
Copy link
Owner

escaped commented Jan 11, 2021

Hey, that's a very good question. The reason this error comes up is, that Django stores datetime objects as UTC and "requires" a valid timezone for every datetime object. I think there is no easy way to solve this as it looks like timezone information is most of the time not available and we cannot derive this information purely from the EXIF data; stored GPS location might be helpful. Though, I suppose, most photos are not geotagged.

I would suggest, that you implement a custom get_datetime method, which either hardcodes the timezone (eg. by using the one defined in your project) or derives it somehow from the EXIF information. Or maybe something completely different, as the correct solution to this problem depends on your use case.

Anyway, we should definitely update the documentation and suggest a "simple fix may be incorrect" fix for this issue (eg. using make_aware()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docs help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants