Fixes #21358: Prevent exception when sorting by Token column #390

Closed
opened 2026-04-05 16:29:01 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @adionit7 on 2/10/2026

Fixes

Closes #21358

Summary

Clicking the "Token" column header in the API Tokens table triggers a FieldError because token is a Python property on the model, not a database field. django-tables2 attempts to pass it to Django's ORM order_by(), which fails.

Changes:

  • Mark the token TemplateColumn in TokenTable as orderable=False, consistent with how other non-field columns are handled in the codebase (e.g. can_view, can_add, can_change, can_delete in ObjectPermissionTable)
  • Add a regression test for TokenTable that verifies all orderable columns can be sorted without raising exceptions, following the existing pattern in circuits/tests/test_tables.py and vpn/tests/test_tables.py
*Originally created by @adionit7 on 2/10/2026* ## Fixes Closes #21358 ## Summary Clicking the "Token" column header in the API Tokens table triggers a `FieldError` because `token` is a Python property on the model, not a database field. django-tables2 attempts to pass it to Django's ORM `order_by()`, which fails. **Changes:** - Mark the `token` `TemplateColumn` in `TokenTable` as `orderable=False`, consistent with how other non-field columns are handled in the codebase (e.g. `can_view`, `can_add`, `can_change`, `can_delete` in `ObjectPermissionTable`) - Add a regression test for `TokenTable` that verifies all orderable columns can be sorted without raising exceptions, following the existing pattern in `circuits/tests/test_tables.py` and `vpn/tests/test_tables.py`
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#390