Uri - that's a great upgrade path (or should I say, non-upgrade path). 
Agree with `VALIDATE_MODELS_BY_DEFAULT`.

Rails also skips validations for some operations, like `update_column`, but 
they are prominently marked to use with caution, and the other ORMs i've 
used follow a similar pattern. bulk_create sounds like there's legitimate 
reason to not validate everything, seems reasonable to exclude it so long 
as there's a prominent "use with caution" statement in the docs.
On Wednesday, October 5, 2022 at 8:35:36 PM UTC-7 Uri wrote:

>
> אורי
> u...@speedy.net
>
>
> On Thu, Oct 6, 2022 at 6:11 AM Aaron Smith <aa...@aaronsmith.co> wrote:
>
>> 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.
>>
>
> +1
>
> I would suggest having a setting "VALIDATE_MODELS_BY_DEFAULT", which is 
> true or false (true by default), whether to call full_clean() on save(), 
> with an option to call it with "validate=True" or "validate=False" to 
> override this default. Maybe also allow changing the default for specific 
> models.
>
> This is similar to forms that have `def save(self, commit=True):`, and you 
> can call them with "commit=True" or "commit=False" to save or not save the 
> results to the database. I also suggest that VALIDATE_MODELS_BY_DEFAULT 
> will be true by default from some specific future version of Django, so 
> that if users don't want it, they will have to manually set it to false.
>
> We should still remember that there are bulk actions such as bulk_create() 
> or update(), that bypass save() completely, so we have to decide how to 
> handle them if we want our data to be always validated.
>
> 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/4f51341e-bc60-4675-a749-0c60dd9108fbn%40googlegroups.com.
          • ... Aaron Smith
          • ... James Bennett
          • ... Aaron Smith
          • ... James Bennett
          • ... Aaron Smith
          • ... James Bennett
          • ... Jure Erznožnik
          • ... Aaron Smith
          • ... Shai Berger
    • ... 'Barry Johnson' via Django developers (Contributions to Django itself)
  • Re... Aaron Smith

Reply via email to