אורי
u...@speedy.net

On Thu, Sep 29, 2022 at 11:04 AM Carlton Gibson <carlton.gib...@gmail.com>
wrote:

>
> On Thursday, 29 September 2022 at 06:29:30 UTC+2 aa...@aaronsmith.co
> 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.
>>
>
I haven't received the original message but only the reply from Carlton
Gibson.

In Speedy Net, all the models inherit from a BaseModel which inherits
from ValidateModelMixin which runs self.full_clean() on save().
https://github.com/speedy-net/speedy-net/blob/master/speedy/core/base/models.py#L7-L16

I was surprised that this is not a default in Django and I think it should
be - models should validate their values before saving to the database.

I also disabled bulk actions such as bulk_create() to avoid saving to the
database without calling save().

Personally, I think this is a must in Django - calling save() for each
instance and calling self.full_clean() to validate data in save().

Uri Rodberg, Speedy Net.



> --
> 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/566b4706-4075-485b-9122-eca24d3b67fcn%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/566b4706-4075-485b-9122-eca24d3b67fcn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CABD5YeH3jb_7soEcMKM5qdHyvqWxXDCA3%3D%3DZ%2BPBC47YMtTAggg%40mail.gmail.com.

Reply via email to