Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

johtso
Copy link
Contributor

@johtso johtso commented Mar 18, 2015

Fixes #2710

How does this look?

@jpadilla jpadilla added this to the 3.1.1 Release milestone Mar 18, 2015
@xordoquy xordoquy modified the milestones: 3.1.1 Release, 3.1.2 Release Mar 19, 2015
Copy link
Contributor

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() == '':

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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

@lovelydinosaur
Copy link
Contributor

Superseeded by #3073.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CharField: allow_blank=False in combination with trim_whitespace=True does not behave as expected
4 participants