﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37357	Admin date_hierarchy raises an unhandled exception (500) on an out-of-range year	Philip Sørensen	Philip Sørensen	"A changelist for a ModelAdmin with date_hierarchy set raises an uncaught exception (HTTP 500) when the <field>__year query parameter is out of range,
  instead of the intended IncorrectLookupParameters (which the changelist view turns into a harmless redirect to ?e=1).

In django/contrib/admin/views/main.py, ChangeList.get_filters() wraps only the  datetime(...) construction in try/except ValueError. The to_date computation that follows is outside the try, and datetime() can raise OverflowError rather than ValueError:

  * ?<datefield>__year=9999 — datetime(9999, 1, 1) succeeds, then to_date = from_date.replace(year=from_date.year + 1) raises ""ValueError: year 10000 is out of range"" (outside the try).
  * ?<datefield>__year=99999999999999999999 — datetime(...) raises ""OverflowError: Python int too large to convert to C long"" (not caught by except ValueError).

Any authenticated staff user with view permission on such a model can trigger it, and date_hierarchy is a very common admin configuration. Django already
handles OverflowError for this same year-out-of-range int->datetime parsing pattern in views/generic/dates.py, views/static.py, template/defaultfilters.py, and contrib/auth/views.py; the admin copy is the inconsistent one.

Fix: catch (ValueError, OverflowError) and move the to_date computation inside the try. A patch with a regression test in tests/admin_changelist follows as a PR."	Bug	assigned	contrib.admin	6.1	Normal		date_hierarchy admin changelist	Philip Sørensen	Accepted	1	0	0	0	0	0
