Repository: Onemind-Services-LLC/netbox-secrets (language: python)

Issue:
[Bug]: API get /secret-roles/?name=XXX doesn't work
### NetBox Secrets plugin version

v1.8.2

### NetBox version

v3.5.2

### Steps to Reproduce

GET with any name filter always fails. For example:

```
curl -X GET "https://netbox/api/plugins/secrets/secret-roles/?name=XXX" -H "Authorization: Token XXX" -H "Accept: application/json; indent=4" -H "Content-Type: application/json"
{
    "name": [
        "“XXX” is not a valid value."
```

Using id as filter works.

### Expected Behavior

Get specified role.

### Observed Behavior

`"“XXX” is not a valid value."` error.


Discussion / hints:

Fix patch:
diff --git a/netbox_secrets/filtersets.py b/netbox_secrets/filtersets.py
index 84b8aa8..1410665 100644
--- a/netbox_secrets/filtersets.py
+++ b/netbox_secrets/filtersets.py
@@ -23,7 +23,7 @@ class SecretRoleFilterSet(NetBoxModelFilterSet):
         method='search',
         label='Search',
     )
-    name = django_filters.ModelMultipleChoiceFilter(queryset=SecretRole.objects.all(), field_name='name')
+    name = MultiValueCharFilter(lookup_expr='iexact')
 
     class Meta:
         model = SecretRole
diff --git a/netbox_secrets/forms/filterset.py b/netbox_secrets/forms/filterset.py
index a5e54a6..5842c36 100644
--- a/netbox_secrets/forms/filterset.py
+++ b/netbox_secrets/forms/filterset.py
@@ -1,13 +1,13 @@
 from django import forms
 from django.contrib.contenttypes.models import ContentType
 from django.utils.translation import gettext as _
+
 from netbox.forms import NetBoxModelFilterSetForm
 from utilities.forms.fields import (
     ContentTypeMultipleChoiceField,
     DynamicModelMultipleChoiceField,
     TagFilterField,
 )
-
 from ..constants import *
 from ..models import Secret, SecretRole
 
@@ -20,7 +20,7 @@
 class SecretRoleFilterForm(NetBoxModelFilterSetForm):
     model = SecretRole
     q = forms.CharField(required=False, label=_('Search'))
-    name = DynamicModelMultipleChoiceField(queryset=SecretRole.objects.all(), required=False)
+    id = DynamicModelMultipleChoiceField(queryset=SecretRole.objects.all(), required=False, label=_('Roles'))
 
 
 class SecretFilterForm(NetBoxModelFilterSetForm):


Test patch:
diff --git a/netbox_secrets/tests/test_filters.py b/netbox_secrets/tests/test_filters.py
index 1d241dc..c4d1a4c 100644
--- a/netbox_secrets/tests/test_filters.py
+++ b/netbox_secrets/tests/test_filters.py
@@ -1,9 +1,9 @@
-from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Site
 from django.test import TestCase
-from virtualization.models import Cluster, ClusterType, VirtualMachine
 
+from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Site
 from netbox_secrets.filtersets import *
 from netbox_secrets.models import Secret, SecretRole
+from virtualization.models import Cluster, ClusterType, VirtualMachine
 
 
 class SecretRoleTestCase(TestCase):
@@ -25,7 +25,7 @@ def test_id(self):
 
     def test_name(self):
         name = SecretRole.objects.all()
-        params = {'name': [name[0].pk, name[1].pk]}
+        params = {'name': [name[0].name, name[1].name]}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
     def test_slug(self):