אורי 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/CABD5YeGHLfzA%3DV%3DosAFM1wnitJ6R20sqc5ddVCCWarBv%2Bk1j3A%40mail.gmail.com.