MultiValueNumberFilter does not support custom field integer values #5585

Closed
opened 2025-12-29 19:29:47 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Oct 29, 2021).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.0.8

Python version

3.7

Steps to Reproduce

The following script can be pasted into the NetBox shell (manage.py nbshell) for a demonstration of the root issue.

import django_filters
from dcim.models import Site
from utilities.filters import MultiValueNumberFilter


class MyFilterSet(django_filters.FilterSet):
    asn = MultiValueNumberFilter()
    cf_foo = MultiValueNumberFilter(
        field_name='custom_field_data__foo'
    )
    class Meta:
        model = Site
        fields = ['asn']


filterset1 = MyFilterSet({'asn': ['123', '456']}, Site.objects.all())
filterset2 = MyFilterSet({'cf_foo': ['123', '456']}, Site.objects.all())

print(filterset1.qs.query)
print(filterset2.qs.query)

This issue was observed during work on #6615. See my comment here.

Expected Behavior

The WHERE clause of the second query should match on the integer values 123 and 456.

WHERE (("dcim_site"."custom_field_data" -> foo) = 123 OR ("dcim_site"."custom_field_data" -> foo) = 456)

Observed Behavior

The query instead matches on the string representations of these values:

WHERE (("dcim_site"."custom_field_data" -> foo) = "123" OR ("dcim_site"."custom_field_data" -> foo) = "456")
Originally created by @jeremystretch on GitHub (Oct 29, 2021). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.0.8 ### Python version 3.7 ### Steps to Reproduce The following script can be pasted into the NetBox shell (`manage.py nbshell`) for a demonstration of the root issue. ``` import django_filters from dcim.models import Site from utilities.filters import MultiValueNumberFilter class MyFilterSet(django_filters.FilterSet): asn = MultiValueNumberFilter() cf_foo = MultiValueNumberFilter( field_name='custom_field_data__foo' ) class Meta: model = Site fields = ['asn'] filterset1 = MyFilterSet({'asn': ['123', '456']}, Site.objects.all()) filterset2 = MyFilterSet({'cf_foo': ['123', '456']}, Site.objects.all()) print(filterset1.qs.query) print(filterset2.qs.query) ``` This issue was observed during work on #6615. See my comment [here](https://github.com/netbox-community/netbox/pull/7678#issuecomment-954811979). ### Expected Behavior The `WHERE` clause of the second query should match on the integer values `123` and `456`. ``` WHERE (("dcim_site"."custom_field_data" -> foo) = 123 OR ("dcim_site"."custom_field_data" -> foo) = 456) ``` ### Observed Behavior The query instead matches on the string representations of these values: ``` WHERE (("dcim_site"."custom_field_data" -> foo) = "123" OR ("dcim_site"."custom_field_data" -> foo) = "456") ```
adam added the type: bugstatus: accepted labels 2025-12-29 19:29:47 +01:00
adam closed this issue 2025-12-29 19:29:47 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5585