Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#2674 closed defect (fixed)

[patch] entering an invalid day of month for DateField and DateTimeField fields results in NULL value

Reported by: Gary Wilson <gary.wilson@…> Owned by: adrian
Component: contrib.admin Version: master
Severity: normal Keywords:
Cc: gary.wilson@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If you try to enter a date where the day is out of range for the month, like 2006-11-31, django will try to insert a NULL value for that field. These dates get past the isValidANSIDate validator's regular expression. Maybe it would be best to use another validator that uses datetime, as it knows that this is an invalid date...

>>> datetime.datetime(2006,11,31)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: day is out of range for month

and isValidANSIDate could use a simpler regular expression that just checks for a YYYY-MM-DD format.

Attachments (1)

dates.diff (2.1 KB) - added by Gary Wilson <gary.wilson@…> 8 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 Changed 8 years ago by anonymous

  • Summary changed from entering an invalid day of month for DateField and DateTimeFields fields results in NULL value to entering an invalid day of month for DateField and DateTimeField fields results in NULL value

Changed 8 years ago by Gary Wilson <gary.wilson@…>

comment:2 Changed 8 years ago by Gary Wilson <gary.wilson@…>

  • Summary changed from entering an invalid day of month for DateField and DateTimeField fields results in NULL value to [patch] entering an invalid day of month for DateField and DateTimeField fields results in NULL value

comment:3 Changed 8 years ago by mtredinnick

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

(In [3815]) Fixed #2674 -- Added stricter date validation so that things like 2006-11-31
are caught. Thanks, Gary Wilson.

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.