Code

Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#7014 closed (fixed)

Newforms dates crash for < year 1900

Reported by: Simon Litchfield <simon@…> Owned by: nobody
Component: Forms Version: master
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: UI/UX:

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@…> 6 years ago.
Patch to raise ValidationError instead of ValueError for dates before 1900

Download all attachments as: .zip

Change History (9)

comment:1 Changed 6 years ago by Simon Litchfield <simon@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Sorry, duplicate on #1443

comment:2 Changed 6 years ago by Simon Litchfield <simon@…>

  • Cc simon@… added
  • Has patch set
  • Resolution duplicate deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to 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.

Changed 6 years ago by Simon Litchfield <simon@…>

Patch to raise ValidationError instead of ValueError for dates before 1900

comment:3 Changed 6 years ago by julianb

  • milestone set to 1.0

comment:4 Changed 6 years ago by jacob

  • milestone changed from 1.0 to post-1.0

Not a 1.0 bug.

comment:5 Changed 6 years ago by julianb

Okay, sorry, then bug != bug :D

comment:6 Changed 6 years ago by anonymous

  • Cc nreilly@… added

comment:7 Changed 5 years ago by Alex

  • Resolution set to fixed
  • Status changed from reopened to 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)

comment:8 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.