Hi On 4/18/19 2:07 PM, Václav Řehák wrote: > As a veteran Django user, I am quite used to it but as I work on > financial project (with strong requirements on data consistency) with a > team of senior developers kind of new to Django I face a lot of > confusion about why does Django let us save invalid data (actually last > week I spent almost 3 days on fixes caused forgotten calls to full_clean > and on data migration to clean up the mess). If it was possible, e.g. in > settings, to force model validation in save(), it would help us a lot. You can make an abstract model with an overriden save() that calls full_clean() and inherit all your models from it. However, remember that this does not cover all database writes. For example, update() on a queryset does not call save(). For this reason, I don't think it is a good idea. It just gives developers a false sense of security. Instead, make sure to validate all input at the application boundary (e.g. using forms).
If data integrity is really important, also consider using database-level constraints. This can be done using raw SQL from a migration. In Django 2.2, there also is https://docs.djangoproject.com/en/2.2/ref/models/constraints/. -- René Fleschenberg -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/8ce3915a-de41-8fee-c36e-078d003b1677%40fleschenberg.net. For more options, visit https://groups.google.com/d/optout.
