Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved DateField.to_python() to catch invalid dates like Feb. 31

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3242 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0d14498ee00fb505f919410a0513452817ffced9 1 parent c9032ab
Adrian Holovaty adrianholovaty authored
Showing with 4 additions and 1 deletion.
  1. +4 −1 django/db/models/fields/__init__.py
5 django/db/models/fields/__init__.py
View
@@ -406,7 +406,10 @@ def to_python(self, value):
if isinstance(value, datetime.date):
return value
validators.isValidANSIDate(value, None)
- return datetime.date(*time.strptime(value, '%Y-%m-%d')[:3])
+ try:
+ return datetime.date(*time.strptime(value, '%Y-%m-%d')[:3])
+ except ValueError:
+ raise validators.ValidationError, gettext('Enter a valid date in YYYY-MM-DD format.')
def get_db_prep_lookup(self, lookup_type, value):
if lookup_type == 'range':
Please sign in to comment.
Something went wrong with that request. Please try again.