Opened 3 months ago

Closed 3 months ago

#35337 closed Bug (invalid)

argument of type 'NoneType' is not iterable, when show facets and change_view is overwritten in ModelAdmin

Reported by: dz Owned by: nobody
Component: contrib.admin Version: 5.0
Severity: Normal Keywords:
Cc: dz Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Natalia Bidart)

Hello,

Django==5.0.3
@admin.register(LicitacionItem)
class LicitacionItemAdmin(admin.ModelAdmin):

    list_select_related = ('licitacion', 'categoria',
                           'proveedor', 'producto', 'licitacion_detalle')

    raw_id_fields = ('licitacion', 'categoria',
                     'proveedor', 'producto', 'licitacion_detalle')

    search_fields = ["CodigoExterno", 'search']

    show_facets = admin.ShowFacets.ALLOW

    list_filter = [
        ('licitacion__date', admin.DateFieldListFilter),
        ('licitacion__FechaCierre', admin.DateFieldListFilter),
        'licitacion__CodigoEstado',
        'active',
        'licitacion_detalle__CodigoTipo',
        'licitacion_detalle__Tipo',
        'licitacion_detalle__TipoConvocatoria',
        'licitacion_detalle__CodigoTipo']

    def change_view(self, request, object_id, extra_context=None):
        self.exclude = ('active', 'analizado', 'touch', 'search')
        return super(LicitacionItemAdmin, self).change_view(request, object_id, extra_context)

when clicking on an item (enter change view), without activating show facets: there are no errors.

when clicking on an item (enter change view), with show facets activated: argument of type 'NoneType' is not iterable (see attached file with the trace)

By completely removing the change_view function, the error does not occur (even if show facets is activated).

Regards

1	Environment:
2	
3	
4	Request Method: GET
5	Request URL: http://192.168.101.60/admin/mpublico/licitacionitem/54719/change/?_changelist_filters=_facets%3DTrue
6	
7	Django Version: 5.0.3
8	Python Version: 3.10.12
9	Installed Applications:
10	['django.contrib.admin',
11	 'django.contrib.auth',
12	 'django.contrib.contenttypes',
13	 'django.contrib.sessions',
14	 'django.contrib.messages',
15	 'django.contrib.staticfiles',
16	 'localflavor',
17	 'mpublico',
18	 'rest_framework',
19	 'rest_framework.authtoken',
20	 'django_celery_results',
21	 'debug_toolbar',
22	 'import_export']
23	Installed Middleware:
24	['debug_toolbar.middleware.DebugToolbarMiddleware',
25	 'django.middleware.security.SecurityMiddleware',
26	 'django.contrib.sessions.middleware.SessionMiddleware',
27	 'django.middleware.common.CommonMiddleware',
28	 'django.middleware.csrf.CsrfViewMiddleware',
29	 'django.contrib.auth.middleware.AuthenticationMiddleware',
30	 'django.contrib.messages.middleware.MessageMiddleware',
31	 'django.middleware.clickjacking.XFrameOptionsMiddleware']
32	
33	
34	
35	Traceback (most recent call last):
36	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
37	    response = get_response(request)
38	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
39	    response = wrapped_callback(request, *callback_args, **callback_kwargs)
40	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/contrib/admin/options.py", line 716, in wrapper
41	    return self.admin_site.admin_view(view)(*args, **kwargs)
42	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
43	    result = _process_exception(request, e)
44	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
45	    response = view_func(request, *args, **kwargs)
46	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/views/decorators/cache.py", line 80, in _view_wrapper
47	    response = view_func(request, *args, **kwargs)
48	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/contrib/admin/sites.py", line 240, in inner
49	    return view(request, *args, **kwargs)
50	  File "/home/erp/erp/erp/mpublico/admin.py", line 98, in change_view
51	    return super(LicitacionItemAdmin, self).change_view(request, object_id, extra_context)
52	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1948, in change_view
53	    return self.changeform_view(request, object_id, form_url, extra_context)
54	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/utils/decorators.py", line 48, in _wrapper
55	    return bound_method(*args, **kwargs)
56	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
57	    result = _process_exception(request, e)
58	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
59	    response = view_func(request, *args, **kwargs)
60	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1804, in changeform_view
61	    return self._changeform_view(request, object_id, form_url, extra_context)
62	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1940, in _changeform_view
63	    return self.render_change_form(
64	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1294, in render_change_form
65	    form_url = add_preserved_filters(
66	  File "/home/erp/erp/venv/lib/python3.10/site-packages/django/contrib/admin/templatetags/admin_urls.py", line 37, in add_preserved_filters
67	    match_url = "/%s" % unquote(url).partition(get_script_prefix())[2]
68	  File "/usr/lib/python3.10/urllib/parse.py", line 667, in unquote
69	    if '%' not in string:
70	
71	Exception Type: TypeError at /admin/mpublico/licitacionitem/54719/change/
72	Exception Value: argument of type 'NoneType' is not iterable

Attachments (3)

error.txt (3.8 KB ) - added by dz 3 months ago.
error trace
models.py (10.5 KB ) - added by dz 3 months ago.
app_files.zip (12.6 KB ) - added by dz 3 months ago.

Download all attachments as: .zip

Change History (11)

by dz, 3 months ago

Attachment: error.txt added

error trace

comment:1 by dz, 3 months ago

Description: modified (diff)

comment:2 by dz, 3 months ago

Description: modified (diff)

comment:3 by dz, 3 months ago

Description: modified (diff)

comment:4 by Natalia Bidart, 3 months ago

Description: modified (diff)
Type: UncategorizedBug

Hola! Thank you for your report.

Could you please attach your models (or similar models) that would make this a complete reproducible example?

Thank you!

by dz, 3 months ago

Attachment: models.py added

comment:5 by dz, 3 months ago

Hi,
I have attached a file with relevant models for the Bug.
Regards

comment:6 by Natalia Bidart, 3 months ago

Hello, thank you for attaching your models.py. I see that the file is quite big and it depends on other modules/helpers that are not provided. Could you please provide, instead, a minimal models.py and a minimal admin.py to reproduce? That will be of great help for us and it will allow us to triage this ticket more effectively.

by dz, 3 months ago

Attachment: app_files.zip added

comment:7 by dz, 3 months ago

Full versions have been attached.

comment:8 by Natalia Bidart, 3 months ago

Keywords: facets change view removed
Resolution: invalid
Status: newclosed

I did some extra debugging and noticed that you are overriding change_view in an incorrect manner. See the change_view docs:

 ModelAdmin.change_view(request, object_id, form_url='', extra_context=None)

your change_view is not correctly accepting the form_url kwarg and is not passing it along, so it ends up being None.

Since the goal of this issue tracker is to track issues about Django itself, and your issue is located in your custom code, I'll be closing this ticket as invalid following the ticket triaging process. If you have further questions about how to use Django, please use any of the user support channels from this link.

Cheers! Natalia.

Note: See TracTickets for help on using tickets.
Back to Top