#7014 closed (fixed)
Newforms dates crash for < year 1900
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | newforms dates datetime date year 1900 | |
Cc: | simon@…, nreilly@… | 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
See below trace. Fair enough dates before 1900 aren't supported, but they should raise a ValidationError rather than a ValueError, so the app doesn't fall over.
Traceback (most recent call last): File "/home/littlealma/lib/python2.5/django/core/handlers/base.py", line 82, in get_response response = callback(request, *callback_args, **callback_kwargs) File "./matrix/register.py", line 68, in _get_order File "./matrix/register.py", line 140, in reg_agent File "/home/littlealma/lib/python2.5/django/newforms/models.py", line 56, in save_instance instance.save() File "./matrix/models.py", line 1088, in save File "/home/littlealma/lib/python2.5/django/db/models/base.py", line 233, in save db_values = [f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, False)) for f in non_pks] File "/home/littlealma/lib/python2.5/django/db/models/fields/__init__.py", line 547, in get_db_prep_save value = value.strftime('%Y-%m-%d') ValueError: year=1234 is before 1900; the datetime strftime() methods require year >= 1900
Attachments (1)
Change History (9)
comment:1 by , 17 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
comment:2 by , 17 years ago
Cc: | added |
---|---|
Has patch: | set |
Resolution: | duplicate |
Status: | closed → reopened |
Triage Stage: | Unreviewed → Design decision needed |
Changed my mind again. Regardless of the outcome of #1443, newforms should not crash on dates before 1900, in the same way I can type 'asdfasdfe' into a date field and not have it crash.
Patch with tests attached.
by , 17 years ago
Attachment: | newforms-dates-1900.diff added |
---|
Patch to raise ValidationError instead of ValueError for dates before 1900
comment:3 by , 16 years ago
milestone: | → 1.0 |
---|
comment:6 by , 16 years ago
Cc: | added |
---|
comment:7 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
This has been fixed at some point:
In [1]: from django import forms In [5]: forms.DateField().clean('1/1/1801') Out[5]: datetime.date(1801, 1, 1) In [6]: forms.DateTimeField().clean('10/10/1801 14:30') Out[6]: datetime.datetime(1801, 10, 10, 14, 30)
Note:
See TracTickets
for help on using tickets.
Sorry, duplicate on #1443