Skip to content
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

Exception with multiselect custom field and query="null" #13606

Closed
candlerb opened this issue Aug 30, 2023 · 1 comment · Fixed by #14607
Closed

Exception with multiselect custom field and query="null" #13606

candlerb opened this issue Aug 30, 2023 · 1 comment · Fixed by #14607
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@candlerb
Copy link
Contributor

NetBox version

v3.5.9

Python version

3.8

Steps to Reproduce

  1. 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"
  2. 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.

image

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:

@candlerb candlerb added the type: bug A confirmed report of unexpected behavior in the application label Aug 30, 2023
@jeremystretch jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available labels Aug 31, 2023
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions github-actions bot added the pending closure Requires immediate attention to avoid being closed for inactivity label Nov 30, 2023
@jeremystretch jeremystretch self-assigned this Dec 14, 2023
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed pending closure Requires immediate attention to avoid being closed for inactivity labels Dec 14, 2023
@jeremystretch jeremystretch removed the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label Dec 26, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants