It sounds like there is little support for this being the default. But I'd 
like to propose something that might satisfy the different concerns:

1) A `validate` kwarg for `save()`, defaulted to `False`. This maintains 
backwards compatibility and also moves the validation behavior users coming 
to Django from other frameworks likely expect, in a more user friendly way 
than overriding save to call `full_clean()`.

And/or...

2) An optional Django setting (`VALIDATE_MODELS_DEFAULT`?) to change the 
default behavior to `True`. The `validate` kwarg above would override this 
per call, allowing unvalidated saves when necessary.

These changes would be simple, backwards compatible, and give individual 
projects the choice to make Django behave like other ORMs with regard to 
validation. This being the Django developers mailing list I should not be 
surprised that most people here support the status quo, but in my personal 
experience, having had this conversation with dozens of coworkers over the 
years - 100% of them expressed a strong desire for Django to do this 
differently.
On Wednesday, September 28, 2022 at 9:29:30 PM UTC-7 Aaron Smith wrote:

> Why doesn't Django validate Models on save()?
>
> I am aware that full_clean() is called when using ModelForms. But most web 
> app development these days, and every django app I've ever worked with, are 
> headless APIs. The default behavior is dangerous for the naive developer.
>
> Bringing View-level concepts such as forms or serializers down into celery 
> tasks and management commands breaks separation of concerns, and having 
> multiple validation implementations at different layers in the app is 
> fraught with divergence and unexpected behavior.
>
> It's not right. The data store layer should protect the validity of the 
> data.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/004c2b9b-6e36-4061-b860-17eb7ebee15en%40googlegroups.com.

Reply via email to