Skip to content

IPAM FilterSet: filter_present_in_vrf method returns queryset.none instead of calling it when VRF is None #19677

@pheus

Description

@pheus

Deployment Type

Self-hosted

NetBox Version

v4.3.2

Python Version

3.11

Steps to Reproduce

  1. Launch the NetBox shell:

    python3 manage.py nbshell
  2. 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)
  3. Observe the result when vrf is None.

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.

@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()

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

No one assigned

    Labels

    status: needs triageThis issue is awaiting triage by a maintainertype: bugA confirmed report of unexpected behavior in the application

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions