﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28555	Inconsistent empty value for EmailField(blank=True, null=True) due to strip after check for empty value	Olav Morken	Josh Schneier	"Hi,

I just noticed that if I enter a single space in an EmailField in a ModelForm where the backing model field is {{{EmailField(blank=True, null=True)}}}, the value is stored as an empty string. On the other hand, if I don't enter anything in the field, it is stored as a {{{None}}} value.

Looking at the code (https://github.com/django/django/blob/1.11.4/django/forms/fields.py#L234-L241), I think the cause is that it first checks for empty values, and then strips the string.

To reproduce this behavior, try something like:

{{{#!python
# models.py
from django.db import models

class SomeUser(models.Model):
    address = models.EmailField(null=True, blank=True)


# views.py
import pprint
from django import forms
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from .models import SomeUser

class SomeUserForm(forms.ModelForm):
    class Meta:
        fields = [ 'address' ]
        model = SomeUser

@csrf_exempt
def test_view(request):
    form = SomeUserForm(request.POST)
    some_user = form.save()
    return HttpResponse(pprint.pformat(some_user.address) + ""\n"")
}}}

Testing this with {{{curl}}} gives something like this:
{{{
$ curl -XPOST -d address= http://127.0.0.1:1253/test
None
curl -XPOST -d address=%20 http://127.0.0.1:1253/test
u''
}}}
"	Bug	closed	Forms	dev	Normal	fixed		Tim Martin	Ready for checkin	1	0	0	0	0	0
