Skip to content
Browse files

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

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent c9032ab commit 0d14498ee00fb505f919410a0513452817ffced9 @adrianholovaty adrianholovaty committed
Showing with 4 additions and 1 deletion.
  1. +4 −1 django/db/models/fields/
5 django/db/models/fields/
@@ -406,7 +406,10 @@ def to_python(self, value):
if isinstance(value,
return value
validators.isValidANSIDate(value, None)
- return*time.strptime(value, '%Y-%m-%d')[:3])
+ try:
+ return*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':

0 comments on commit 0d14498

Please sign in to comment.
Something went wrong with that request. Please try again.