On Friday, October 18, 2013 5:28:21 AM UTC+3, Karen Tracey wrote: > > > On Wed, Oct 16, 2013 at 7:03 PM, Russell Keith-Magee < > [email protected] <javascript:>> wrote: > >> >>> 1) Without taking backwards compatibility into consideration, is it >>> reasonable to expect field validation automatically upon calling >>> model.save() >>> >> >> Yes. Based on the original discussions (as I recall them), this wasn't in >> question -- the problem was entirely backwards compatibility. >> >> > > > Wasn't there also concern for double validation performed during form > clean and then model instance save? >
Another problem is performance - some database validations aren't cheap. Uniqueness checks and foreign key checks do generate database queries, and both of these are already validated in the DB (well, in any real DB). In many realistic cases model.save() could get multiple times more expensive than what it is now. In addition model validation on save() still doesn't give you any guarantee that your data in the DB is actually correct. Using .update() will still pass any validation. And, for any validation that checks data from referenced models, it is going to be very likely that concurrent transactions will lead to invalid data in the DB. Getting plain referential integrity right under concurrency is surprisingly hard, and getting more advanced constraints right is still harder. If you want your data consistent you want your validations done in the DB. So, personally I am more interested in trying to have more constraints automatically created in the DB. Of course, not all types of validation are easy to do in SQL, for example converting random python validations to DB triggers is pretty much impossible. But there are also validations that would be straightforward to do (value in choices for example). I guess I am -0 on automatic model validation on .save(). In any case I would make the default mode model._meta flag so that you could choose the default per model. - Anssi -- You received this message because you are subscribed to the Google Groups "Django developers" 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 http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/17e77e96-f977-4000-aaf2-1ee11fb49f92%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
