Skip to content

Exception when sorting by Token #21358

@xtprox

Description

@xtprox

NetBox Edition

NetBox Community

NetBox Version

v4.5.0

Python Version

3.12

Steps to Reproduce

  1. Login to the site
  2. Click on the profile icon and select "API Tokens"
  3. In the tokens table click on the "TOKEN" column (in order to toggle sorting)

Expected Behavior

Sorting order changed to TOKEN column.

Observed Behavior

<class 'django.core.exceptions.FieldError'>

Cannot resolve keyword 'token' into field. Choices are: allowed_ips, created, description, enabled, expires, hmac_digest, id, key, last_used, pepper_id, plaintext, user, user_id, version, write_enabled

The request which yielded the above error is shown below:
GET https://netbox-test.dtekgroup.tek.loc/user/api-tokens/?sort=token
Internal Server Error: /user/api-tokens/

FieldError at /user/api-tokens/
Cannot resolve keyword 'token' into field. Choices are: allowed_ips, created, description, enabled, expires, hmac_digest, id, key, last_used, pepper_id, plaintext, user, user_id, version, write_enabled

Request Method: GET
Request URL: https://nbtest.local/user/api-tokens/?sort=token
Django Version: 5.2.9
Python Executable: /opt/netbox/venv/bin/python3 Python Version: 3.12.3 Python Path: ['/opt/netbox/netbox', '/opt/netbox', '/opt/netbox/venv/bin', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/opt/netbox/venv/lib/python3.12/site-packages']
Server time: Thu, 05 Feb 2026 11:06:26 +0200 Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'django.forms',
 'corsheaders',
 'django_filters',
 'django_htmx',
 'django_tables2',
 'django_prometheus',
 'strawberry_django',
 'mptt',
 'rest_framework',
 'social_django',
 'sorl.thumbnail',
 'taggit',
 'timezone_field',
 'core',
 'account',
 'circuits',
 'dcim',
 'ipam',
 'extras',
 'tenancy',
 'users',
 'utilities',
 'virtualization',
 'vpn',
 'wireless',
 'django_rq',
 'drf_spectacular',
 'drf_spectacular_sidecar']
Installed Middleware:
['corsheaders.middleware.CorsMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 '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',
 'django_htmx.middleware.HtmxMiddleware',
 'netbox.middleware.RemoteUserMiddleware',
 'netbox.middleware.CoreMiddleware',
 'netbox.middleware.MaintenanceModeMiddleware']


Traceback (most recent call last):
  File "/opt/netbox/netbox/netbox/middleware.py", line 128, in __call__
    username = request.META[self.header]
               ^^^^^^^^^^^^^^^^^^^^^^^^^

During handling of the above exception ('HTTP_REMOTE_USER'), another exception occurred:
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/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.12/site-packages/django/views/generic/base.py", line 105, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/contrib/auth/mixins.py", line 73, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/views/generic/base.py", line 144, in dispatch
    return handler(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/account/views.py", line 336, in get
    table.configure(request)
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/netbox/tables/tables.py", line 182, in configure
    self.order_by = ordering
    ^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django_tables2/tables.py", line 532, in order_by
    self.data.order_by(self._order_by)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django_tables2/data.py", line 214, in order_by
    self.data = self.data.order_by(*order_by_accessors)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/query.py", line 1727, in order_by
    obj.query.add_ordering(*field_names)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/sql/query.py", line 2305, in add_ordering
    self.names_to_path(item.split(LOOKUP_SEP), self.model._meta)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1806, in names_to_path
    raise FieldError(
    ^

Exception Type: FieldError at /user/api-tokens/ Exception Value: Cannot resolve keyword 'token' into field. Choices are: allowed_ips, created, description, enabled, expires, hmac_digest, id, key, last_used, pepper_id, plaintext, user, user_id, version, write_enabled Raised during: account.views.UserTokenListView Request information:
USER: admin

GET:
sort = 'token'

If you're testing, any further try to enter the API keys page will result in an error. To clear that, go to the https://<your-netbox-fqdn>/user/api-tokens/?sort= or in your User profile > Preferences click on the checkbox against the TokenTable element in the Table Configurations section and then click Save.

Metadata

Metadata

Assignees

Labels

netboxseverity: lowDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions