django-admin-autocomplete-filter icon indicating copy to clipboard operation
django-admin-autocomplete-filter copied to clipboard

Problem with nplus one package

Open wwarne opened this issue 6 years ago • 3 comments

Thank you for this awesome package. Really helped a lot.

But then I enable nplusone middleware and try to load admin page with autocomplete filter - server returned 500 error

site-packages/nplusone/ext/django/patch.py", line 137, in parse_forward_many_to_one_queryset
    instance = context['kwargs']['instance']
KeyError: 'instance'

The default django-admin ModelAdmin.autocomplete_fields are working without any problems with this middleware, so maybe something from AutocompleteFilter is missing? If you can have a look at this it would be great.

wwarne avatar Dec 18 '18 11:12 wwarne

Does anybody resolve the problem? Or everyone is turned off nplusone and only turn it on when you need it?

DmytroLitvinov avatar Dec 28 '21 10:12 DmytroLitvinov

It is curious to have this error from nplusone reported to the django-admin-autocomplete-filter. The traceback does not show d-a-a-f. No inspection of the error (using pdb for example) is done. It would be useful if one of the people who see the problem could look deeper.

merwok avatar Dec 29 '21 02:12 merwok

It work.

from admin_auto_filters.filters import AutocompleteFilter as BaseAutocompleteFilter
from django.conf import settings

class AutocompleteFilter(BaseAutocompleteFilter):
    def __init__(self, request, params, model, model_admin):
        if 'nplusone.ext.django' in settings.INSTALLED_APPS:
            from nplusone.core import signals

            with signals.ignore(signals.lazy_load):
                super().__init__(request, params, model, model_admin)
        else:
            super().__init__(request, params, model, model_admin)

redlovv avatar Apr 07 '22 07:04 redlovv