Opened 9 years ago

Closed 8 years ago

#3306 closed defect (duplicate)

[patch] tzinfo raises OverflowError for years out of time.mktime supported range

Reported by: ymasuda <ymasuda@…> Owned by: nobody
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:



In django.utils.tzinfo, LocalTimezone._isdst() is calling time.time() to indicate DST status of the timezone.
This causes OverflowError if you put a DateTimeField and list it in Admin.list_display, then save instance with
far future date (namely beyond 2038) and display it in admin site's changelist.

Symptom with example

Assume '' application has following model:

class Bar(models.Model):
    date = models.DateTimeField()
    class Admin:
        list_display = ('date',)

And an user create Bar instance of 3000/01/01:

>>> from import Bar
>>> from datetime import datetime
>>> b = Bar(date=datetime(3000, 1, 1)) 

The instance is saved silently (even in admin's Create New Bar view), but your changelist view
(http://yourdomain/admin/foo/bar/) will raise OverflowError:

OverflowError at /admin/foo/bar/
mktime argument out of range

Request Method:	GET
Request URL:	http://localhost:8000/admin/foo/bar/
Exception Type:	OverflowError
Exception Value:	mktime argument out of range
Exception Location:	/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/utils/ in _isdst, line 51

Proposed resolution

The attached patch includes modification in LocalTimezone._isdst() so that the years out of
mktime-supported range (1970-2037) will be clipped as 1970 or 2037.
Applying this patch will allow user to specify years in range (1900-9999).


As an alternative resolution, Date(Time)Field may validate its value to reject years out of (1970-2037).

Attachments (1)

preventing_datefilter_overflow.diff (750 bytes) - added by ymasuda <ymasuda@…> 9 years ago.
Patch on django.utils.tzinfo to prevent Date(Time)Field's overflowerror

Download all attachments as: .zip

Change History (4)

Changed 9 years ago by ymasuda <ymasuda@…>

Patch on django.utils.tzinfo to prevent Date(Time)Field's overflowerror

comment:1 Changed 9 years ago by ymasuda <ymasuda@…>

  • Component changed from Admin interface to Core framework

comment:2 Changed 9 years ago by SmileyChris

  • Triage Stage changed from Unreviewed to Design decision needed

Needs a decision on which way to go with this.

comment:3 Changed 8 years ago by ubernostrum

  • Resolution set to duplicate
  • Status changed from new to closed

This looks like a duplicate of #1443, which is older and has more discussion.

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