Opened 10 years ago

Closed 10 years ago

Last modified 10 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 Holovaty
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@…> 10 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 Changed 10 years ago by anonymous

Summary: entering an invalid day of month for DateField and DateTimeFields fields results in NULL valueentering an invalid day of month for DateField and DateTimeField fields results in NULL value

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

Attachment: dates.diff added

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

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

comment:3 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

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

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