On 16 Apr 2019, at 20:47, Will Gordon <wpg...@gmail.com> wrote:
I can't seem to find a good reason for this. And I could foresee this preventing potential mistakes. I'm not proposing to actually change the implementation, I guess I'm just looking for the reason of it.
--
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-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
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/97ae2f12-bc27-403d-8b76-f456a63fc0d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The idea is that you generally always have to do extensive validation when accepting user input through a form. These validations could require additional database queries or other somewhat expensive lookups (especially with validate unique).
However if you are loading data from a trusted source, e.g:
for row in your_csv_file:
instance = Model(**row)
instance.save()
Then there is no need to call that potentially slow full_clean()
. There is not much value in slowing down all .save()
’s needlessly - the developer should know when it’s appropriate to run validations and can run full_clean()
when needed.
So the validation is cheaper when performed by ModelForm, as opposed to the Model?
--
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-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
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/8d929b8e-b0e9-4a88-b796-26f00266f729%40googlegroups.com.
> It's mostly for performance reasons, since validation can be expensive.
Really? My memory was that it was (a) backward compatibility [model
validation was added later], and (b) practicality [try catching
everywhere in your code you save a model, and enforce catching
validation exceptions there].