Opened 6 weeks ago

Last modified 7 days ago

#37417 assigned Bug

Date-based generic views crash with OverflowError at the date range limits

Reported by: Philip Sørensen Owned by: Philip Sørensen
Component: Generic views Version: 6.1
Severity: Normal Keywords:
Cc: Philip Sørensen Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

#28209 made the date-based generic views return a 404 rather than crash when given an out-of-range date. The fix caught the ValueError from date.replace() in _get_next_year() and _get_next_month(), and _get_next_week() catches OverflowError. However, two other paths do timedelta arithmetic at datetime.date.max / datetime.date.min with no handling, and they still crash with OverflowError: date value out of range (HTTP 500):

  • DayMixin._get_next_day() — e.g. a DayArchiveView with allow_empty=True at /9999/dec/31/. This is reachable with the URL pattern from the docs, <int:year>/<str:month>/<int:day>/. (#28209 comment 5 lists _get_next_day() as affected, but the committed fix didn't touch it.)
  • _get_next_prev() computing the previous period with allow_empty=True: get_current(start - timedelta(days=1)). This crashes for YearArchiveView, MonthArchiveView, WeekArchiveView and DayArchiveView when the date is in year 1, e.g. year="0001". (A <int:year> converter strips the leading zeros, so this needs a 4-digit regex or str pattern.)

Patch: raise Http404(_("Date out of range")) in both places. That is the same behavior and message as the existing _get_next_week() handling and test_year_out_of_range. An alternative for the "previous" case would be returning None (no previous link), but I kept it consistent with the #28209 approach.

Change History (7)

comment:1 by Ishan Kumar, 6 weeks ago

Reproduced on main (f1d11117c6). DayArchiveView with allow_empty=True at 9999-12-31 crashes with OverflowError: date value out of range, and so do the year/month/week/day archive views for year 0001 with allow_empty=True (and the DateTimeField case). The tests from PR 22133 fail with OverflowError on main and pass with the patch.

comment:2 by Ishan Kumar, 6 weeks ago

Triage Stage: Unreviewed → Accepted

comment:3 by Ahmed Ibrahim, 6 weeks ago

Owner: set to Ahmed Ibrahim
Status: new → assigned

comment:4 by Ahmed Ibrahim, 6 weeks ago

Owner: Ahmed Ibrahim removed
Status: assigned → new

Please make sure to assign yourself when taking a ticket, this was unassigned yet a patch was made 2 days ago

comment:5 by SnippyCodes, 7 days ago

Owner: set to Philip Sørensen
Status: new → assigned

comment:6 by SnippyCodes, 7 days ago

Triage Stage: Accepted → Ready for checkin

comment:7 by SnippyCodes, 7 days ago

  • Verified upper boundary arithmetic at datetime.date.max (year 9999) raises Http404("Date out of range") instead of an unhandled OverflowError (HTTP 500).
  • Verified lower boundary arithmetic at datetime.date.min (year 0001 with allow_empty=True) cleanly raises Http404.
Note: See TracTickets for help on using tickets.
Back to Top