-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
severity: lowDoes not significantly disrupt application functionality, or a workaround is availableDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application
Description
NetBox version
v3.5.9
Python version
3.8
Steps to Reproduce
- Create a custom field of type "multiple selection". Let's say it's called "foo" and is applied to dcim.device, and has allowed values "a,b,c"
- Query
/dcim/devices/?cf_foo=null
Expected Behavior
The request to be processed, or at least ignored. (Ideally it would show devices which have no selection made for the given custom field)
Observed Behavior
A ValueError was raised.
Here is the backtrace:
Internal Server Error: /dcim/devices/
ValueError at /dcim/devices/
Cannot use None as a query value
Request Method: GET
Request URL: https://netbox.example.net/dcim/devices/?cf_foo=null
Django Version: 4.1.10
Python Executable: /opt/netbox/venv/bin/python3.8
Python Version: 3.8.10
Python Path: ['/opt/netbox/netbox', '/opt/netbox', '/opt/netbox/venv/bin', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/opt/netbox/venv/lib/python3.8/site-packages']
Server time: Wed, 30 Aug 2023 09:43:17 +0000
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'corsheaders',
'debug_toolbar',
'graphiql_debug_toolbar',
'django_filters',
'django_tables2',
'django_prometheus',
'graphene_django',
'mptt',
'rest_framework',
'social_django',
'taggit',
'timezone_field',
'core',
'circuits',
'dcim',
'ipam',
'extras',
'tenancy',
'users',
'utilities',
'virtualization',
'wireless',
'django_rq',
'drf_spectacular',
'drf_spectacular_sidecar',
'netbox_prometheus_sd.PrometheusSD',
'netbox_topology_views.TopologyViewsConfig']
Installed Middleware:
['graphiql_debug_toolbar.middleware.DebugToolbarMiddleware',
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'netbox.middleware.RemoteUserMiddleware',
'netbox.middleware.CoreMiddleware',
'netbox.middleware.MaintenanceModeMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware']
Traceback (most recent call last):
File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 56, in inner
response = get_response(request)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 103, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/netbox/netbox/netbox/views/generic/base.py", line 77, in dispatch
return super().dispatch(request, *args, **kwargs)
File "/opt/netbox/netbox/utilities/views.py", line 99, in dispatch
return super().dispatch(request, *args, **kwargs)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 142, in dispatch
return handler(request, *args, **kwargs)
File "/opt/netbox/netbox/netbox/views/generic/bulk_views.py", line 130, in get
self.queryset = self.filterset(request.GET, self.queryset, request=request).qs
File "/opt/netbox/venv/lib/python3.8/site-packages/django_filters/filterset.py", line 230, in qs
qs = self.filter_queryset(qs)
File "/opt/netbox/venv/lib/python3.8/site-packages/django_filters/filterset.py", line 213, in filter_queryset
queryset = self.filters[name].filter(queryset, value)
File "/opt/netbox/venv/lib/python3.8/site-packages/django_filters/filters.py", line 263, in filter
qs = self.get_method(qs)(q)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/query.py", line 1421, in filter
return self._filter_or_exclude(False, args, kwargs)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/query.py", line 1439, in _filter_or_exclude
clone._filter_or_exclude_inplace(negate, args, kwargs)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/query.py", line 1446, in _filter_or_exclude_inplace
self._query.add_q(Q(*args, **kwargs))
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1532, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1562, in _add_q
child_clause, needed_inner = self.build_filter(
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1388, in build_filter
return self._add_q(
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1562, in _add_q
child_clause, needed_inner = self.build_filter(
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1478, in build_filter
condition = self.build_lookup(lookups, col, value)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1308, in build_lookup
raise ValueError("Cannot use None as a query value")
Exception Type: ValueError at /dcim/devices/
Exception Value: Cannot use None as a query value
Raised during: dcim.views.DeviceListView
Request information:
USER: brian
GET:
cf_foo = 'null'
POST: No POST data
FILES: No FILES data
Additional info:
- The queries
cf_foo=nullandcf_foo__n=nullwork with custom fields of type "select" rather than "multiselect" - With multiselect, the query
cf_foo=aworks as expected - With multiselect, the query
cf_foo__n=adoes not work (it has no effect, all devices are shown); similarly,cf_foo__n=nullhas no effect. - Relates to Filter custom field of type 'selection' for value is null or not-null #11538 (comment)
Metadata
Metadata
Assignees
Labels
severity: lowDoes not significantly disrupt application functionality, or a workaround is availableDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application
