pythondjangodjango-modelsdjango-validation

Why doesn't django's model.save() call full_clean()?


I'm just curious if anyone knows if there's good reason why Django's ORM doesn't call full_clean on a model unless it is being saved as part of a model form?

Note that full_clean() will not be called automatically when you call your model’s save() method. You’ll need to call it manually when you want to run one-step model validation for your own manually created models.
- from Django's full_clean doc

(NOTE: quote updated for Django 1.6... previous Django docs had a caveat about ModelForms as well.)

Are there good reasons why people wouldn't want this behavior? I'd think if you took the time to add validation to a model, you'd want that validation run every time the model is saved.

I know how to get everything to work properly, I'm just looking for an explanation.


Solution

  • AFAIK, this is because of backwards compatibility. There are also problems with ModelForms with excluded fields, models with default values, pre_save() signals, etc.

    Sources you might be intrested in: