-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert to internal value before validation #2712
Conversation
if is_empty_value: | ||
return data | ||
|
||
value = self.to_internal_value(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider re-jigging how this works - as it is this kinda confuses me.
Could we just alter the if data == '':
check so that it also checks for whitespace only. Eg: if data == '' or self.trim_whitespace and six.text_type(data).strip() == '':
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why shouldn't we be relying upon validate_empty_values
?
Seems sensible to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forget about the previous comment. Actually, it's the call to to_internal_value that does the trimming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we go with this instead:
value = super(CharField, self).run_validation(value)
if value == '':
if not self.allow_blank:
self.fail('blank')
return value
Superseeded by #3073. |
Fixes #2710
How does this look?