Opened 13 years ago

Closed 13 years ago

#18323 closed Cleanup/optimization (fixed)

Date-based generic views mix dates and datetimes unsafely

Reported by: Aymeric Augustin Owned by: Aymeric Augustin
Component: Generic views Version: dev
Severity: Normal Keywords: refactoring
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Date-based generic views can use either a DateField or a DateTimeField. But the logic of the lookups to handle these two cases is a bit fuzzy. When time zone support is enabled, it isn't correct (or at least, not obviously so).

In order to make the code less fragile, I rewrote much of the interval handling logic.

This patch:

  • adds some explicit conversions between dates and datetimes, accounting for the current time zone,
  • makes the code generally clearer and possibly more correct — off-by-the-UTC-offset bugs are less likely when USE_TZ = True.

As a side effect, this patch is likely to fix two bugs:

  • an egde case where accessing next_day/week/month/year on a DateTimeField could 404 even with allow_empty = False due to approximative filtering,
  • #17192.

Attachments (1)

18323.patch (12.5 KB ) - added by Aymeric Augustin 13 years ago.

Download all attachments as: .zip

Change History (3)

by Aymeric Augustin, 13 years ago

Attachment: 18323.patch added

comment:1 by Aymeric Augustin, 13 years ago

Owner: changed from nobody to Aymeric Augustin

comment:2 by Aymeric Augustin <aymeric.augustin@…>, 13 years ago

Resolution: fixed
Status: newclosed

In [20e697368219603599649bc67aea5e087caedeae]:

Fixed #18323 -- Refactored date arithmetic

in date based generic views, in order to deal properly with both
DateFields and DateTimeFields.

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