-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Warnings on schema generation for FilterSets #12257
Comments
drf-spectacular can not infer the parameter type for django_filters.ModelChoiceFilter fields. They should be added via extend_schema_field. For present_in_vrf_id and present_in_vrf the annotation is added to the field directly to preserve the field description in the schema. The description is duplicated because once there is an override, no further introspection is done. Possible diff: diff --git a/netbox/ipam/filtersets.py b/netbox/ipam/filtersets.py
index a128b6acc..459f847d0 100644
--- a/netbox/ipam/filtersets.py
+++ b/netbox/ipam/filtersets.py
@@ -6,6 +6,9 @@ from django.db.models import Q
from django.utils.translation import gettext as _
from netaddr.core import AddrFormatError
+from drf_spectacular.utils import extend_schema_field
+from drf_spectacular.types import OpenApiTypes
+
from dcim.models import Device, Interface, Region, Site, SiteGroup
from netbox.filtersets import ChangeLoggedModelFilterSet, OrganizationalModelFilterSet, NetBoxModelFilterSet
from tenancy.filtersets import TenancyFilterSet
@@ -284,17 +287,17 @@ class PrefixFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
to_field_name='rd',
label=_('VRF (RD)'),
)
- present_in_vrf_id = django_filters.ModelChoiceFilter(
+ present_in_vrf_id = extend_schema_field({'type': 'string', 'description': 'VRF'})(django_filters.ModelChoiceFilter(
queryset=VRF.objects.all(),
method='filter_present_in_vrf',
label=_('VRF')
- )
- present_in_vrf = django_filters.ModelChoiceFilter(
+ ))
+ present_in_vrf = extend_schema_field({'type': 'string', 'description': 'VRF (RD)'})(django_filters.ModelChoiceFilter(
queryset=VRF.objects.all(),
method='filter_present_in_vrf',
to_field_name='rd',
label=_('VRF (RD)'),
- )
+ ))
region_id = TreeNodeMultipleChoiceFilter(
queryset=Region.objects.all(),
field_name='site__region',
@@ -526,17 +529,17 @@ class IPAddressFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
to_field_name='rd',
label=_('VRF (RD)'),
)
- present_in_vrf_id = django_filters.ModelChoiceFilter(
+ present_in_vrf_id = extend_schema_field({'type': 'string', 'description': 'VRF'})(django_filters.ModelChoiceFilter(
queryset=VRF.objects.all(),
method='filter_present_in_vrf',
label=_('VRF')
- )
- present_in_vrf = django_filters.ModelChoiceFilter(
+ ))
+ present_in_vrf = extend_schema_field({'type': 'string', 'description': 'VRF (RD)'})(django_filters.ModelChoiceFilter(
queryset=VRF.objects.all(),
method='filter_present_in_vrf',
to_field_name='rd',
label=_('VRF (RD)'),
- )
+ ))
device = MultiValueCharFilter(
method='filter_device',
field_name='name',
@@ -727,6 +730,7 @@ class FHRPGroupFilterSet(NetBoxModelFilterSet):
Q(name__icontains=value)
)
+ @extend_schema_field(OpenApiTypes.STR)
def filter_related_ip(self, queryset, name, value):
"""
Filter by VRF & prefix of assigned IP addresses.
@@ -941,9 +945,11 @@ class VLANFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
pass
return queryset.filter(qs_filter)
+ @extend_schema_field(OpenApiTypes.STR)
def get_for_device(self, queryset, name, value):
return queryset.get_for_device(value)
+ @extend_schema_field(OpenApiTypes.STR)
def get_for_virtualmachine(self, queryset, name, value):
return queryset.get_for_virtualmachine(value) |
The remaining warning is Here is a potential solution but I have not been able to get this working: tfranzel/drf-spectacular#873 (comment) |
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. |
This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary. |
NetBox version
v3.5-beta
Python version
3.10
Steps to Reproduce
Generate schema using, e.g.
Expected Behavior
No warnings are displayed.
Observed Behavior
Currently several warnings are displayed for filtersets:
The text was updated successfully, but these errors were encountered: