Opened 19 years ago
Closed 18 years ago
#3306 closed defect (duplicate)
[patch] tzinfo raises OverflowError for years out of time.mktime supported range
| Reported by: | 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: | no | UI/UX: | no |
Description
Summary
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 'sandbox.foo' 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 sandbox.foo.models import Bar >>> from datetime import datetime >>> b = Bar(date=datetime(3000, 1, 1)) >>> b.save() >>>
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/tzinfo.py 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).
Note
As an alternative resolution, Date(Time)Field may validate its value to reject years out of (1970-2037).
Attachments (1)
Change History (4)
by , 19 years ago
| Attachment: | preventing_datefilter_overflow.diff added |
|---|
comment:1 by , 19 years ago
| Component: | Admin interface → Core framework |
|---|
comment:2 by , 19 years ago
| Triage Stage: | Unreviewed → Design decision needed |
|---|
Needs a decision on which way to go with this.
comment:3 by , 18 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
This looks like a duplicate of #1443, which is older and has more discussion.
Patch on django.utils.tzinfo to prevent Date(Time)Field's overflowerror