{"action":"created","issue":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2937","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2937/labels{/name}","comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2937/comments","events_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2937/events","html_url":"https://github.com/tomchristie/django-rest-framework/issues/2937","id":76468581,"number":2937,"title":"Setting `allow_null=True` on CharField returns `None` as unicode string","user":{"login":"foresmac","id":3628189,"avatar_url":"https://avatars.githubusercontent.com/u/3628189?v=3","gravatar_id":"","url":"https://api.github.com/users/foresmac","html_url":"https://github.com/foresmac","followers_url":"https://api.github.com/users/foresmac/followers","following_url":"https://api.github.com/users/foresmac/following{/other_user}","gists_url":"https://api.github.com/users/foresmac/gists{/gist_id}","starred_url":"https://api.github.com/users/foresmac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/foresmac/subscriptions","organizations_url":"https://api.github.com/users/foresmac/orgs","repos_url":"https://api.github.com/users/foresmac/repos","events_url":"https://api.github.com/users/foresmac/events{/privacy}","received_events_url":"https://api.github.com/users/foresmac/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-05-14T19:42:55Z","updated_at":"2015-05-15T08:39:03Z","closed_at":"2015-05-14T20:33:26Z","body":"You can set `allow_null=True` on a CharField, but `None` gets converted to a string before going to the validator. I believe the problem is the `to_internal_value()` function, which coerces `None` to a unicode string:\r\n\r\nhttps://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/fields.py#L588:\r\n```python\r\n    def to_internal_value(self, data):\r\n        value = six.text_type(data)\r\n        return value.strip() if self.trim_whitespace else value\r\n```\r\n\r\nIf you run this on `None`, you just a get the string `u'None'`:\r\n``` python\r\n>>> from six import text_type\r\n>>> text_type(None)\r\nu'None'\r\n>>> \r\n```\r\n\r\nI suggest changing it like so:\r\n``` python\r\n    def to_internal_value(self, data):\r\n        if data is None and self.allow_null:\r\n            return None\r\n        value = six.text_type(data)\r\n        return value.strip() if self.trim_whitespace else value\r\n```"},"comment":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/comments/102319560","html_url":"https://github.com/tomchristie/django-rest-framework/issues/2937#issuecomment-102319560","issue_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2937","id":102319560,"user":{"login":"tomchristie","id":647359,"avatar_url":"https://avatars.githubusercontent.com/u/647359?v=3","gravatar_id":"","url":"https://api.github.com/users/tomchristie","html_url":"https://github.com/tomchristie","followers_url":"https://api.github.com/users/tomchristie/followers","following_url":"https://api.github.com/users/tomchristie/following{/other_user}","gists_url":"https://api.github.com/users/tomchristie/gists{/gist_id}","starred_url":"https://api.github.com/users/tomchristie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomchristie/subscriptions","organizations_url":"https://api.github.com/users/tomchristie/orgs","repos_url":"https://api.github.com/users/tomchristie/repos","events_url":"https://api.github.com/users/tomchristie/events{/privacy}","received_events_url":"https://api.github.com/users/tomchristie/received_events","type":"User","site_admin":false},"created_at":"2015-05-15T08:39:03Z","updated_at":"2015-05-15T08:39:03Z","body":"@foresmac Yeah, went against that initially as wanted it to default to same behavior as Django's test client. Don't know if the other way around woulda been better or not."}}