archive_month generic view returns item from next month
|Reported by:||scottb||Owned by:||nobody|
|Severity:||Keywords:||archive_month, generic views|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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 datetime.date, 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.
Change History (5)
comment:1 Changed 9 years ago by
|Patch needs improvement:||unset|