Skip to content
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

Closed
wants to merge 1 commit into from

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
if is_empty_value:
return data

value = self.to_internal_value(data)
Copy link
Member

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
Collaborator

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
Collaborator

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
Collaborator

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

@tomchristie
Copy link
Member

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