-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix BaseFilterSet not using multiple choice filters #3342
Fix BaseFilterSet not using multiple choice filters #3342
Conversation
# Conflicts: # nautobot/circuits/tests/test_filters.py # nautobot/core/filters.py # nautobot/core/tests/test_filters.py # nautobot/dcim/tests/test_filters.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have any impact on the use of these filters in the UI, or how they are presented in the advanced filtering form?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would like to clarify the impact of this on the UI and forms before it gets merged.
With screenshots? :) |
@@ -1087,7 +1087,7 @@ def test_outer_unit(self): | |||
with self.subTest(): | |||
self.assertEqual(Rack.objects.exclude(outer_unit="").count(), 3) | |||
with self.subTest(): | |||
params = {"outer_unit": RackDimensionUnitChoices.UNIT_MILLIMETER} | |||
params = {"outer_unit": [RackDimensionUnitChoices.UNIT_MILLIMETER]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be able to change most of these affected tests to entries in generic_filter_test
rather than separate test functions now that these are multi-value filters, though it may take a bit of modifying to the test data to make it diverse enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not need to be done on this PR right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't block this PR on waiting for this change but it should be a pretty straightforward one to do. Fine with me if you want to open a new issue or add a comment on #3213 calling out these tests.
Closes: #3214
What's Changed
BaseFilterSet.filter_for_lookup
to add logic that checks if the lookup type is exact and if the field has attributechoices
(as only IntegerField/CharField with choices can have this attribute), and returns MulipleChoiceFilter if the conditions are meet.elif existing filter.extra.get("choices")
because we now expect the choice field to beMulipleChoiceFilter
, which would require all relevant lookup expressions of aMulipleChoiceFilter
to be included.TODO