Carl,

All ORMs I have worked with allow you to bypass validations when necessary. 
Sometimes you have to. But the path of greatest naivety should be as safe 
as possible. I cannot even imagine how many lost hours and economic damages 
have occurred because the easy path is the dangerous path. I have been 
there for some of it - data consistency problems are horrible.

On Thursday, September 29, 2022 at 5:36:29 PM UTC-7 carl.j...@gmail.com 
wrote:

> On Thu, Sep 29, 2022 at 6:19 PM Curtis Maloney <cur...@tinbrain.net> 
> wrote:
>
>> On Thu, 29 Sep 2022, at 14:29, Aaron Smith wrote:
>>
>> Why doesn't Django validate Models on save()?
>>
>>
>> The short answer is: backwards compatibility.
>>
>> Model level validation hasn't always been a thing, with Django initially 
>> depending primarily on Form validation.
>>
>> Since it hadn't _always_ been there, it wasn't possible to introduce it, 
>> enforce it, and not break most apps out there.
>>
>> There was so much code written that generally assumed it could call 
>> `save()` and not have to catch validation errors.
>>
>> For what it's worth, I'm all in favor of making it run on `save()` ... 
>> updating the documentation and preparing the community is going to be a 
>> mammoth task, however. A safe course through this will take some very 
>> careful planning.
>>
>
> Another factor that should be considered is that the Django ORM gives you 
> plenty of ways to update your database (eg bulk updates on a queryset) that 
> clearly cannot materialize and validate every object in the queryset. So is 
> it better to consistently say “the ORM doesn’t validate, forms do,” or 
> better to say “the ORM will validate on Model.save() but not in various 
> other cases, so you still can’t really rely on the ORM to enforce model 
> validation invariants consistently.”
>
> Carl
>
>>

-- 
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/b3fe241c-914c-47d4-8bd1-ef5b646b8c2bn%40googlegroups.com.

Reply via email to