Opened 16 years ago

Closed 15 years ago

Last modified 15 years ago

#7014 closed (fixed)

Newforms dates crash for < year 1900

Reported by: Simon Litchfield <simon@…> 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)

newforms-dates-1900.diff (2.0 KB ) - added by Simon Litchfield <simon@…> 16 years ago.
Patch to raise ValidationError instead of ValueError for dates before 1900

Download all attachments as: .zip

Change History (9)

comment:1 by Simon Litchfield <simon@…>, 16 years ago

Resolution: duplicate
Status: newclosed

Sorry, duplicate on #1443

comment:2 by Simon Litchfield <simon@…>, 16 years ago

Cc: simon@… added
Has patch: set
Resolution: duplicate
Status: closedreopened
Triage Stage: UnreviewedDesign 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 Simon Litchfield <simon@…>, 16 years ago

Attachment: newforms-dates-1900.diff added

Patch to raise ValidationError instead of ValueError for dates before 1900

comment:3 by Julian Bez, 16 years ago

milestone: 1.0

comment:4 by Jacob, 16 years ago

milestone: 1.0post-1.0

Not a 1.0 bug.

comment:5 by Julian Bez, 16 years ago

Okay, sorry, then bug != bug :D

comment:6 by anonymous, 16 years ago

Cc: nreilly@… added

comment:7 by Alex Gaynor, 15 years ago

Resolution: fixed
Status: reopenedclosed

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)

comment:8 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

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