[Django] #28209: Date-based generic views can fail with ValueError: year is out of range

76 views
Skip to first unread message

Django

unread,
May 15, 2017, 12:52:42 PM5/15/17
to django-...@googlegroups.com
#28209: Date-based generic views can fail with ValueError: year is out of range
-----------------------------------------+------------------------
Reporter: Tim Graham | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Test to reproduce:
{{{ #!diff
diff --git a/tests/generic_views/test_dates.py
b/tests/generic_views/test_dates.
index bf462b4..76d4b2b 100644
--- a/tests/generic_views/test_dates.py
+++ b/tests/generic_views/test_dates.py
@@ -661,6 +661,9 @@ class DateDetailViewTests(TestDataMixin, TestCase):
self.assertEqual(res.context['book'], b)
self.assertTemplateUsed(res, 'generic_views/book_detail.html')

+ def test_year_out_of_range(self):
+ self.client.get('/dates/books/9999/')
+
def test_invalid_url(self):
with self.assertRaises(AttributeError):
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28209>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 15, 2017, 3:12:52 PM5/15/17
to django-...@googlegroups.com
#28209: Date-based generic views can fail with ValueError: year is out of range
-------------------------------+------------------------------------

Reporter: Tim Graham | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by aditbiswas1):

* has_patch: 0 => 1


Comment:

added a PR for this [https://github.com/django/django/pull/8508 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/28209#comment:1>

Django

unread,
May 15, 2017, 3:13:34 PM5/15/17
to django-...@googlegroups.com
#28209: Date-based generic views can fail with ValueError: year is out of range
-------------------------------------+-------------------------------------

Reporter: Tim Graham | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aditbiswas1):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/28209#comment:2>

Django

unread,
May 15, 2017, 3:14:59 PM5/15/17
to django-...@googlegroups.com
#28209: Date-based generic views can fail with ValueError: year is out of range
-------------------------------------+-------------------------------------

Reporter: Tim Graham | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aditbiswas1):

updated MonthMixin aswell which will throw the same error when crossing
year 9999

--
Ticket URL: <https://code.djangoproject.com/ticket/28209#comment:3>

Django

unread,
May 15, 2017, 3:33:52 PM5/15/17
to django-...@googlegroups.com
#28209: Date-based generic views can fail with ValueError: year is out of range
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Adit
| Biswas
Type: Bug | Status: assigned

Component: Generic views | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adit Biswas):

* status: new => assigned
* owner: nobody => Adit Biswas


--
Ticket URL: <https://code.djangoproject.com/ticket/28209#comment:4>

Django

unread,
May 15, 2017, 4:01:22 PM5/15/17
to django-...@googlegroups.com
#28209: Date-based generic views can fail with ValueError: year is out of range
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Adit
| Biswas
Type: Bug | Status: assigned
Component: Generic views | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Adit Biswas):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/28209#comment:5>

Django

unread,
May 15, 2017, 4:11:15 PM5/15/17
to django-...@googlegroups.com
#28209: Date-based generic views can fail with ValueError: year is out of range
-------------------------------+---------------------------------------

Reporter: Tim Graham | Owner: Adit Biswas
Type: Bug | Status: assigned
Component: Generic views | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by Adit Biswas):

* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/28209#comment:6>

Django

unread,
May 26, 2017, 7:16:21 PM5/26/17
to django-...@googlegroups.com
#28209: Date-based generic views can fail with ValueError: year is out of range
-------------------------------+---------------------------------------
Reporter: Tim Graham | Owner: Adit Biswas
Type: Bug | Status: assigned
Component: Generic views | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------

Comment (by Tim Graham):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28209#comment:7>

Django

unread,
May 29, 2017, 1:54:40 AM5/29/17
to django-...@googlegroups.com
#28209: Date-based generic views can fail with ValueError: year is out of range
-------------------------------+---------------------------------------
Reporter: Tim Graham | Owner: Adit Biswas
Type: Bug | Status: assigned
Component: Generic views | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------

Comment (by Adit Biswas):

added a PR for this [https://github.com/django/django/pull/8509 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/28209#comment:8>

Django

unread,
May 29, 2017, 1:54:55 AM5/29/17
to django-...@googlegroups.com
#28209: Date-based generic views can fail with ValueError: year is out of range
-------------------------------------+-------------------------------------

Reporter: Tim Graham | Owner: Adit
| Biswas
Type: Bug | Status: assigned
Component: Generic views | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adit Biswas):

* needs_better_patch: 1 => 0


* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/28209#comment:9>

Django

unread,
May 30, 2017, 1:27:10 PM5/30/17
to django-...@googlegroups.com
#28209: Date-based generic views can fail with ValueError: year is out of range
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Adit
| Biswas
Type: Bug | Status: closed

Component: Generic views | Version: 1.11
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"c2eea61dff44b16caab04928d582b856c2b8b615" c2eea61d]:
{{{
#!CommitTicketReference repository=""
revision="c2eea61dff44b16caab04928d582b856c2b8b615"
Fixed #28209 -- Made date-based generic views return a 404 rather than
crash when given an out of range date.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28209#comment:10>

Django

unread,
May 30, 2017, 1:32:39 PM5/30/17
to django-...@googlegroups.com
#28209: Date-based generic views can fail with ValueError: year is out of range
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Adit
| Biswas
Type: Bug | Status: closed
Component: Generic views | Version: 1.11
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"4e675999d530692f96745f5a54ba0376acd39e22" 4e67599]:
{{{
#!CommitTicketReference repository=""
revision="4e675999d530692f96745f5a54ba0376acd39e22"
[1.11.x] Fixed #28209 -- Made date-based generic views return a 404 rather


than crash when given an out of range date.

Backport of c2eea61dff44b16caab04928d582b856c2b8b615 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28209#comment:11>

Reply all
Reply to author
Forward
0 new messages