Limit ModelFormSet queryset parameter
|Reported by:||sbaechler||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
This error happened to us a while ago (with Django 1.2.3) and I don't know if the issue has been fixed since. But I didn't find anything in the history.
The issue was this. One of our servers was starting to not react for several seconds a few times every day. The processor load went up to 200% and it had to use disk cache because it run out of RAM. It took us a while until we found the issue:
A few ModelFormSets were instantiated without the queryset parameter. Just POST data, which was sufficient for the app to work. There was no performance issue while the database had only a few entries but once it reached a few thousand, it brought the server down.
The issue was resolved once I added the queryset parameter. I don't know if it was caused because of the missing queryset parameter or the fact that the default manager returned a few thousand entries.
But it should be possible to add a fail-safe or warning if the queryset and data that comes in via POST don't match. Isn't it possible to get the primary keys from the POST data?
The formsets were created using the modelformset_factory. I have attached the view code.