-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Labels
severity: lowDoes not significantly disrupt application functionality, or a workaround is availableDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application
Milestone
Description
Deployment Type
Self-hosted
NetBox Version
v4.3.2
Python Version
3.11
Steps to Reproduce
-
Launch the NetBox shell:
python3 manage.py nbshell
-
Run the following:
from ipam.models import IPAddress from ipam.filtersets import IPAddressFilterSet qs = IPAddress.objects.all() filterset = IPAddressFilterSet() # Intentionally passing `None` as the `vrf` parameter result = filterset.filter_present_in_vrf(qs, 'present_in_vrf', None) print(result)
-
Observe the result when
vrfisNone.
Expected Behavior
When vrf is None, the method should return an empty queryset like:
<RestrictedQuerySet []>Observed Behavior
The method instead returns a method reference:
<bound method QuerySet.none of <RestrictedQuerySet [...]>>This happens because queryset.none is returned without being called - i.e., it's missing parentheses. This causes unexpected behavior when the return value is used downstream, potentially leading to runtime issues or incorrect query evaluation.
netbox/netbox/ipam/filtersets.py
Lines 449 to 456 in 2680f85
| @extend_schema_field(OpenApiTypes.STR) | |
| def filter_present_in_vrf(self, queryset, name, vrf): | |
| if vrf is None: | |
| return queryset.none | |
| return queryset.filter( | |
| Q(vrf=vrf) | | |
| Q(vrf__export_targets__in=vrf.import_targets.all()) | |
| ).distinct() |
netbox/netbox/ipam/filtersets.py
Lines 730 to 736 in 2680f85
| def filter_present_in_vrf(self, queryset, name, vrf): | |
| if vrf is None: | |
| return queryset.none | |
| return queryset.filter( | |
| Q(vrf=vrf) | | |
| Q(vrf__export_targets__in=vrf.import_targets.all()) | |
| ).distinct() |
Metadata
Metadata
Assignees
Labels
severity: lowDoes not significantly disrupt application functionality, or a workaround is availableDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application