Skip to content

MultiValueNumberFilter does not support custom field integer values #7690

@jeremystretch

Description

@jeremystretch

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")

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions