-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent Django Admin default queries on primary media tables in production #4344
Comments
Reopening to signify my request for clarification about the status of this issue and the solution implemented in #4349 (comment) |
@sarayourfriend can we close this issue, or did you want to keep it open until we can remove the functions that the associated issue created? I think #4386 maybe have also helped accomplish this. |
I want to prevent I think it could be accomplished by creating a custom object manager for the media models that prevents selecting more than the maximum number of rows we need for search. To me the problem isn't with the implementation of the Django admin forms we have now. The problem is that it's even possible. I want to make it impossible to cause this problem in production, not just something we try to cautiously avoid. |
FWIW I think what's more destructive, even if a limit is provided, is |
Sounds good! Whatever the features we shouldn't use on those tables, the object manager can block them. Can you update the issue body with what you think those features that need to be blocked are? Is it just order by? |
I was looking into this and although I found that creating a custom object manager for limiting the number of rows returned works for the initial query, and even though it still returns a class MediaManager(models.Manager):
def get_queryset(self):
return super().get_queryset()[:5] # example number The documentation says:
We have to resort to being alert to possible queries that can get out of control. We also can't remove the sort statements because they are used in admin views. If anyone has any alternatives I'd be happy to hear them. For now, I'm closing this issue. |
@krysal the only alternative I can think of that would accomplish this is to subclass |
Description
On several occasions now, we've run into production resource issues with our database due to Django Admin performing some default query against our (massive) primary media tables (e.g. #970).
Recent changes to the reporting admin (specifically #4254) have added new views that are also selecting the primary media tables in order to generate the UI. These are incredibly useful for local testing, but are actively harmful for production.
We should alter the logic for these fields so that the automatic completion only occurs locally and does not occur in production. This will help prevent issues from occurring from simply visiting pages in Django Admin in production.Going forward (per @sarayourfriend's comment #4344 (comment)), we should create a custom object manager for the media models that ensures the following things:
ORDER BY
is not used on the base media tablesLIMIT
is always defined for queries on the media tablesThis would prevent us from erroneously adding naive queries that could impact production in the future, even if we add the functionality for the query in a naive way.
The text was updated successfully, but these errors were encountered: