Opened 10 years ago

Closed 10 years ago

#6888 closed (invalid)

archive_month generic view returns item from next month

Reported by: scottb Owned by: nobody
Component: Generic views Version: master
Severity: Keywords: archive_month, generic views
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I found the archive_month date based generic view can return objects from the next month. e.g. the view for objects in February will return objects for 1st March as well. It seems to be an issue when the model has a DateField, a DateTimeField set to a, or a DateTimeField set to a datetime with time zero/midnight. Essentially any date on the first of the month where time is zero.

The archive_month view uses range e.g. 1st February to 1st March. This was done for ticket #992 long ago. If the object in March is a datetime with at least 1 second past midnight, it works fine. But when it's midnight (or a date instead of datetime), it falls in to the February range.

Attached is a patch to the regression tests to show what I mean. Also attached are a couple of possible fixes:

Fix 1: checks the year and month instead of using range.
Fix 2: uses gte and lt instead of range.

The same issue may affect the archive_week view. If I'm on the right track, I can write tests/patches for that.

Attachments (3)

month_tests.diff (4.1 KB) - added by scottb 10 years ago.
fix_1_lte_gt.diff (1.0 KB) - added by scottb 10 years ago.
fix_2_year_month.diff (1.0 KB) - added by scottb 10 years ago.

Download all attachments as: .zip

Change History (5)

Changed 10 years ago by scottb

Attachment: month_tests.diff added


Changed 10 years ago by scottb

Attachment: fix_1_lte_gt.diff added

Changed 10 years ago by scottb

Attachment: fix_2_year_month.diff added

comment:1 Changed 10 years ago by Ramiro Morales

What database backend(s) are you using? which version? what exact revision of Django did you use for these tests?

comment:2 Changed 10 years ago by Marc Fargas

Resolution: invalid
Status: newclosed

From the bug description I can only read "your database server is screwed", as the reporter did not provide furter requested information I'm closing as invalid.

If you can provide the missing information to help us reproduce this bug, feel free to reopen this ticket (if it's a Django problem).


Note: See TracTickets for help on using tickets.
Back to Top