#28209 closed Bug (fixed)
Date-based generic views can fail with ValueError: year is out of range
Reported by: | Tim Graham | Owned by: | Adit Biswas |
---|---|---|---|
Component: | Generic views | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | 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
Test to reproduce:
-
tests/generic_views/test_dates.py
diff --git a/tests/generic_views/test_dates.py b/tests/generic_views/test_dates. index bf462b4..76d4b2b 100644
a b class DateDetailViewTests(TestDataMixin, TestCase): 661 661 self.assertEqual(res.context['book'], b) 662 662 self.assertTemplateUsed(res, 'generic_views/book_detail.html') 663 663 664 def test_year_out_of_range(self): 665 self.client.get('/dates/books/9999/') 666 664 667 def test_invalid_url(self): 665 668 with self.assertRaises(AttributeError): 666 669 self.client.get("/dates/books/2008/oct/01/nopk/")
Traceback:
File "/home/tim/code/django/django/views/generic/dates.py", line 58, in _get_next_year return date.replace(year=date.year + 1, month=1, day=1) ValueError: year is out of range
I think returning a 404 response is the correct thing to do. Other mixins besides YearMixin
may be affected.
Change History (10)
comment:3 by , 8 years ago
updated MonthMixin aswell which will throw the same error when crossing year 9999
comment:4 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 8 years ago
Sorry, I'm not sure if I've done enough. Waiting for some discussion around this before I continue making changes.
basically datetime will throw value errors whenever the year crosses 9999.
Wherever a datetime is manipulated to increment the date to cross 10000 will be affected.
YearMixin._get_next_year(self, date) MonthMixin._get_next_month(self, date) DayMixin._get_next_day(self, date) WeekMixin._get_next_week(self, date)
While 404 would be an appropriate response for dates crossing the Year 9999
shouldnt the dates between 01-01-9999 and 31-12-9999 be handled appropriately
if I throw 404 for each mixin the behaviour will be slightly odd. since
/dates/books/9999/ will throw a 404 but /dates/books/9999/01 will not
comment:6 by , 8 years ago
Patch needs improvement: | set |
---|
comment:7 by , 7 years ago
I think preventing a crash is of main importance at this point. Django will probably be obsolete before handling dates with year 9999 is a practical problem.
comment:9 by , 7 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
added a PR for this PR