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

Closed
opened 2025-12-29 21:42:45 +01:00 by adam · 1 comment
Owner

Originally created by @pheus on GitHub (Jun 6, 2025).

Originally assigned to: @pheus on GitHub.

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.

2680f855ff/netbox/ipam/filtersets.py (L449-L456)

2680f855ff/netbox/ipam/filtersets.py (L730-L736)

Originally created by @pheus on GitHub (Jun 6, 2025). Originally assigned to: @pheus on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.3.2 ### Python Version 3.11 ### Steps to Reproduce 1. Launch the NetBox shell: ```bash python3 manage.py nbshell ``` 2. Run the following: ```python 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: ```python <RestrictedQuerySet []> ``` ### Observed Behavior The method instead returns a **method reference**: ```python <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. https://github.com/netbox-community/netbox/blob/2680f855ffaef0a876bac811d4cd56198ae3f329/netbox/ipam/filtersets.py#L449-L456 https://github.com/netbox-community/netbox/blob/2680f855ffaef0a876bac811d4cd56198ae3f329/netbox/ipam/filtersets.py#L730-L736
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:42:45 +01:00
adam closed this issue 2025-12-29 21:42:45 +01:00
Author
Owner

@pheus commented on GitHub (Jun 6, 2025):

I'd be happy to submit a fix for this.

@pheus commented on GitHub (Jun 6, 2025): I'd be happy to submit a fix for this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11274