﻿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
22224	Non-nullable blank string-based model field validation doesn't prevent or clean `None`	Simon Charette	Jacob Walls	"Since [https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.null we discourage the use of NULLable string-based fields] the assumed way of holding text that might be empty would be to use the `blank` option.

In this case I would expect `full_clean` to raise a `ValidationError` when an empty non-nullable field is assigned `None`:

{{{#!python
from django.db import models

class A(models.Model):
    b = models.CharField(blank=True)

a = A(b=None)
a.full_clean()  # Passes
a.save()  # Integrity error
}}}

Unfortunately specifying `blank=True` disable all validation against the `b` field, leading to database integrity error upon calling `save()`. The obvious solution here would be to override `A.clean` to convert `b` to an empty string when it equals `None` but it strikes me as a non trivial change for a quite common use case: correctly allowing a string-based field to be empty.

This is not an issue when cleaning data retrieved from the usual `application/form-url-encoded` `request.GET` or `request.POST` since an empty value is always represented by the empty string. However, in the case of an `application/json` encoded payload one may either provide `None` or `''` (`null` or `''`) to express emptiness. Which will trigger the issue described above.

Attaching a patch that special case the `empty_values` of non-nullable string based fields based on the `empty_strings_allowed` flag. All tests pass on Py2.7/SQLite3."	Cleanup/optimization	closed	Documentation	dev	Normal	fixed			Accepted	1	0	0	0	0	0
