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

Time Zone warning when filtering on the "past 7 days" #873

Closed
ukrutt opened this issue Feb 15, 2018 · 2 comments
Closed

Time Zone warning when filtering on the "past 7 days" #873

ukrutt opened this issue Feb 15, 2018 · 2 comments

Comments

@ukrutt
Copy link

ukrutt commented Feb 15, 2018

When requesting data that's filtered on a "Date range" of "last week", I get a warning in the Django console:

.../.venv/lib/python3.6/site-packages/django/db/models/fields/__init__.py:1393:
RuntimeWarning: DateTimeField Asset.date_added received a naive datetime
(2018-02-08 00:00:00) while time zone support is active.

The reason is that the _truncate function removes time zone info. I am about to open a Pull Request with code that fixes this.

@carltongibson
Copy link
Owner

Hi @ukrutt. Thanks for the report.

Currently DateRangeFilter only really works with DateFields. _truncate is meant to return a date. When that gets converted to a datetime you're not going to have tzinfo.

Your change in #874 has _truncate return a datetime, which is leading to the failure in the filtering for the object create today in the week filtering test. (Exactly why that's not giving the right result would be interesting: what's the zero-hour datetime getting converted back to a date as? — but I haven't had a chance to look at that.)

There shouldn't be any reason this should work both ways. (Django's ChangeList manages it I think.) So I'd be very happy to look a PR solving the issues here.

@carltongibson
Copy link
Owner

DateRangeFilter was reworked in #852. Happy to review if still an issue (perhaps with a test case demonstrating). But closing otherwise

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