Code

Opened 6 years ago

Closed 6 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:

Description

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.

Attachments (3)

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

Download all attachments as: .zip

Change History (5)

Changed 6 years ago by scottb

Tests

Changed 6 years ago by scottb

Changed 6 years ago by scottb

comment:1 Changed 6 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 6 years ago by telenieko

  • Resolution set to invalid
  • Status changed from new to closed

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).

Thanks.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.