mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-21 20:18:38 -06:00
Fixes #21358: Prevent exception when sorting by Token column (#21391)
CI / build (20.x, 3.12) (push) Failing after 12s
CI / build (20.x, 3.13) (push) Failing after 12s
CI / build (20.x, 3.14) (push) Failing after 11s
CodeQL / Analyze (actions) (push) Failing after 1m8s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1m17s
CodeQL / Analyze (python) (push) Failing after 1m19s
CI / build (20.x, 3.12) (push) Failing after 12s
CI / build (20.x, 3.13) (push) Failing after 12s
CI / build (20.x, 3.14) (push) Failing after 11s
CodeQL / Analyze (actions) (push) Failing after 1m8s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1m17s
CodeQL / Analyze (python) (push) Failing after 1m19s
Mark the `token` TemplateColumn as non-orderable since it maps to a Python property rather than a database field, causing a FieldError when django-tables2 attempts to sort by it. Add a regression test for TokenTable following the existing pattern in circuits and vpn test suites.
This commit is contained in:
@@ -24,6 +24,7 @@ class TokenTable(NetBoxTable):
|
||||
token = columns.TemplateColumn(
|
||||
verbose_name=_('token'),
|
||||
template_code=TOKEN,
|
||||
orderable=False,
|
||||
)
|
||||
enabled = columns.BooleanColumn(
|
||||
verbose_name=_('Enabled')
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
from django.test import RequestFactory, tag, TestCase
|
||||
|
||||
from users.models import Token
|
||||
from users.tables import TokenTable
|
||||
|
||||
|
||||
class TokenTableTest(TestCase):
|
||||
@tag('regression')
|
||||
def test_every_orderable_field_does_not_throw_exception(self):
|
||||
tokens = Token.objects.all()
|
||||
disallowed = {'actions'}
|
||||
|
||||
orderable_columns = [
|
||||
column.name for column in TokenTable(tokens).columns
|
||||
if column.orderable and column.name not in disallowed
|
||||
]
|
||||
fake_request = RequestFactory().get("/")
|
||||
|
||||
for col in orderable_columns:
|
||||
for direction in ('-', ''):
|
||||
with self.subTest(col=col, direction=direction):
|
||||
table = TokenTable(tokens)
|
||||
table.order_by = f'{direction}{col}'
|
||||
table.as_html(fake_request)
|
||||
Reference in New Issue
Block a user