Opened 5 years ago

Closed 5 years ago

#18217 closed Bug (fixed)

Date-based generic views use naive datetime objects

Reported by: Mike Yumatov Owned by: Aymeric Augustin
Component: Generic views Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Some date-based generic views (MonthArchiveView, WeekArchiveView, DayArchiveView, TodayArchiveView, DateDetailView) raise time zone warnings if USE_TZ because of using naive datetime objects and date objects in _date_from_string, _month_bounds and _date_lookup_for_field from django.views.generic.dates module.

Attachments (2)

18217-backport.patch (23.5 KB) - added by Aymeric Augustin 5 years ago.
46b082e0-backport.patch (3.5 KB) - added by Aymeric Augustin 5 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 5 years ago by Aymeric Augustin

Resolution: duplicate
Status: newclosed

The warning is a symtom of the actual problem, which is that a "day" or "month" isn't a well defined period of time unless a time zone is also specified.

This problem is covered by #17260.

comment:3 Changed 5 years ago by Aymeric Augustin

Resolution: duplicate
Status: closedreopened

I'm reopening this because some parts may be fixed by using date ranges instead of year/month/day lookups, similar to r17670.

comment:4 Changed 5 years ago by Aymeric Augustin

Owner: changed from nobody to Aymeric Augustin
Status: reopenednew
Triage Stage: UnreviewedAccepted

comment:5 Changed 5 years ago by Aymeric Augustin

Resolution: fixed
Status: newclosed

Fixed in 78ba9670af373f5261f95d6560bfd08425adcaad.

Now, date-based generic views display objects consistently in the current time zone. However, date_list is still off — that's #17260.

comment:6 Changed 5 years ago by Aymeric Augustin

Resolution: fixed
Status: closedreopened
Triage Stage: AcceptedReady for checkin

I'm tempted to backport this commit to 1.4.X. The queryset returned by YearView is wrong when time zone support is enabled, which I would have considered a release blocker for 1.4.

comment:7 Changed 5 years ago by Aymeric Augustin

Resolution: fixed
Status: reopenedclosed

I've written the patch (see attachement), but for the tests to pass, I'd have to backport 46b082e05ccedffeb623028caf70adbaba7bce6f first.

I feel that these changes are quite large for fixing a minor bug (the results are off by the UTC offset only for the year view).

Unless someone's strongly in favor of backporting these two commits, I'll leave it there.

Changed 5 years ago by Aymeric Augustin

Attachment: 18217-backport.patch added

comment:8 Changed 5 years ago by Fantomas42

Hi aaugustin,

I'm strongly in favor of backporting these two commits.

Because without these commits, I cannot complete my migration process for enabling the time zone support without warnings when I run my test suite.

I make an intensive usage of the dates based generic views, that's why I'm doing this request.

Regards

comment:9 Changed 5 years ago by Aymeric Augustin

Resolution: fixed
Status: closedreopened

comment:10 Changed 5 years ago by Aymeric Augustin

I tried backporting both changesets and still I got two test failures.

======================================================================
FAIL: test_aware_datetime_date_detail (regressiontests.generic_views.dates.DateDetailViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/myk/Documents/dev/django-trunk/django/test/utils.py", line 205, in inner
    return test_func(*args, **kwargs)
  File "/Users/myk/Documents/dev/django-trunk/tests/regressiontests/generic_views/dates.py", line 530, in test_aware_datetime_date_detail
    self.assertEqual(res.status_code, 200)
AssertionError: 404 != 200

======================================================================
FAIL: test_aware_datetime_day_view (regressiontests.generic_views.dates.DayArchiveViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/myk/Documents/dev/django-trunk/django/test/utils.py", line 205, in inner
    return test_func(*args, **kwargs)
  File "/Users/myk/Documents/dev/django-trunk/tests/regressiontests/generic_views/dates.py", line 456, in test_aware_datetime_day_view
    self.assertEqual(res.status_code, 200)
AssertionError: 404 != 200

Warnings can be silenced with warnings.filterwarnings if they really bother you, until you upgrade to Django 1.5...

Changed 5 years ago by Aymeric Augustin

Attachment: 46b082e0-backport.patch added

comment:11 Changed 5 years ago by fantomas42@…

Ok aaugustin,

thank you for the information and for your try of a backport.

For the now I will disable the time zone support in my test cases where dates based views are involved.

Regards

comment:12 Changed 5 years ago by Aymeric Augustin

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.
Back to Top