mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-19 09:53:34 -06:00
Guard against superfluous "choices" param in filter class instantiation
This commit is contained in:
parent
f239b2337c
commit
e462e29c30
@ -133,7 +133,7 @@ class BaseFilterSet(django_filters.FilterSet):
|
|||||||
django_filters.ModelChoiceFilter,
|
django_filters.ModelChoiceFilter,
|
||||||
django_filters.ModelMultipleChoiceFilter,
|
django_filters.ModelMultipleChoiceFilter,
|
||||||
TagFilter
|
TagFilter
|
||||||
)) or existing_filter.extra.get('choices'):
|
)):
|
||||||
# These filter types support only negation
|
# These filter types support only negation
|
||||||
return FILTER_NEGATION_LOOKUP_MAP
|
return FILTER_NEGATION_LOOKUP_MAP
|
||||||
|
|
||||||
@ -172,6 +172,7 @@ class BaseFilterSet(django_filters.FilterSet):
|
|||||||
# Create new filters for each lookup expression in the map
|
# Create new filters for each lookup expression in the map
|
||||||
for lookup_name, lookup_expr in lookup_map.items():
|
for lookup_name, lookup_expr in lookup_map.items():
|
||||||
new_filter_name = f'{existing_filter_name}__{lookup_name}'
|
new_filter_name = f'{existing_filter_name}__{lookup_name}'
|
||||||
|
existing_filter_extra = deepcopy(existing_filter.extra)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if existing_filter_name in cls.declared_filters:
|
if existing_filter_name in cls.declared_filters:
|
||||||
@ -179,14 +180,18 @@ class BaseFilterSet(django_filters.FilterSet):
|
|||||||
# create the new filter with the same type because there is no guarantee the defined type
|
# create the new filter with the same type because there is no guarantee the defined type
|
||||||
# is the same as the default type for the field
|
# is the same as the default type for the field
|
||||||
resolve_field(field, lookup_expr) # Will raise FieldLookupError if the lookup is invalid
|
resolve_field(field, lookup_expr) # Will raise FieldLookupError if the lookup is invalid
|
||||||
filter_cls = django_filters.BooleanFilter if lookup_expr == 'empty' else type(existing_filter)
|
if lookup_expr == 'empty':
|
||||||
|
existing_filter_extra.pop('choices', None)
|
||||||
|
filter_cls = django_filters.BooleanFilter
|
||||||
|
else:
|
||||||
|
filter_cls = type(existing_filter)
|
||||||
new_filter = filter_cls(
|
new_filter = filter_cls(
|
||||||
field_name=field_name,
|
field_name=field_name,
|
||||||
lookup_expr=lookup_expr,
|
lookup_expr=lookup_expr,
|
||||||
label=existing_filter.label,
|
label=existing_filter.label,
|
||||||
exclude=existing_filter.exclude,
|
exclude=existing_filter.exclude,
|
||||||
distinct=existing_filter.distinct,
|
distinct=existing_filter.distinct,
|
||||||
**existing_filter.extra
|
**existing_filter_extra
|
||||||
)
|
)
|
||||||
elif hasattr(existing_filter, 'custom_field'):
|
elif hasattr(existing_filter, 'custom_field'):
|
||||||
# Filter is for a custom field
|
# Filter is for a custom field
|
||||||
|
Loading…
Reference in New Issue
Block a user