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 22921,Model.clean_fields incorrectly skips validation for fields where null value is not allowed,silveroff@…,nobody,"I'm curious why does this method skips validation for a field with None value. As a side effect if field has null=False, skipping validation will result in DatabaseError saying that coulmn cannot be null. Why don't we check if None is a valid value for a field, taking into account current status of ``null`` option? This would save developers from nasty bugs and boilerplate in their model forms. {{{ def clean_fields(self, exclude=None): """""" Cleans all fields and raises a ValidationError containing message_dict of all validation errors if any occur. """""" if exclude is None: exclude = [] errors = {} for f in self._meta.fields: if f.name in exclude: continue # Skip validation for empty fields with blank=True. The developer # is responsible for making sure they have a valid value. raw_value = getattr(self, f.attname) if f.blank and raw_value in f.empty_values: continue try: setattr(self, f.attname, f.clean(raw_value, self)) except ValidationError as e: errors[f.name] = e.error_list if errors: raise ValidationError(errors) }}}",Cleanup/optimization,closed,"Database layer (models, ORM)",dev,Normal,invalid,"field validation, model",,Unreviewed,0,0,0,0,0,0