From 536bd37d05a8eeba6f17b64a5d0ad2a207063be8 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 6 Sep 2022 16:37:52 -0700 Subject: [PATCH 1/3] #9231 make empty search work --- netbox/netbox/filtersets.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/netbox/netbox/filtersets.py b/netbox/netbox/filtersets.py index 3a0434592..2dec13d88 100644 --- a/netbox/netbox/filtersets.py +++ b/netbox/netbox/filtersets.py @@ -80,6 +80,10 @@ class BaseFilterSet(django_filters.FilterSet): }, }) + def __init__(self, *args, **kwargs): + self.base_filters = self.get_filters() + super().__init__(*args, **kwargs) + @staticmethod def _get_filter_lookup_dict(existing_filter): # Choose the lookup expression map based on the filter type From 2fe620df7019bf6eb6e5397b85f2e595e2b86768 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 6 Sep 2022 18:04:29 -0700 Subject: [PATCH 2/3] #9231 call class method --- netbox/netbox/filtersets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/netbox/filtersets.py b/netbox/netbox/filtersets.py index 2dec13d88..2e535266d 100644 --- a/netbox/netbox/filtersets.py +++ b/netbox/netbox/filtersets.py @@ -81,7 +81,7 @@ class BaseFilterSet(django_filters.FilterSet): }) def __init__(self, *args, **kwargs): - self.base_filters = self.get_filters() + self.base_filters = self.__class__.get_filters() super().__init__(*args, **kwargs) @staticmethod From 48a907ae4580f77eea74180c826952c8c3d3d5e7 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 7 Sep 2022 08:09:28 -0700 Subject: [PATCH 3/3] #9231 add comment --- netbox/netbox/filtersets.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netbox/netbox/filtersets.py b/netbox/netbox/filtersets.py index 2e535266d..b6776e3c1 100644 --- a/netbox/netbox/filtersets.py +++ b/netbox/netbox/filtersets.py @@ -81,6 +81,9 @@ class BaseFilterSet(django_filters.FilterSet): }) def __init__(self, *args, **kwargs): + # bit of a hack for #9231 - extras.lookup.Empty is registered in apps.ready + # however FilterSet Factory is setup before this which creates the + # initial filters. This recreates the filters so Empty is picked up correctly. self.base_filters = self.__class__.get_filters() super().__init__(*args, **kwargs)