Skip to content
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 advance filter error on multiple custom filter #3574

Merged

Conversation

timizuoebideri1
Copy link
Contributor

Closes: #3391

What's Changed

Error reported was caused by is_single_choice_field returning True for CustomFieldMultiSelectFilter because CustomFieldMultiSelectFilter inherits from django_filters.Filter and not django_filters.MultipleChoiceFilter.

Also fixed an additional bug where the page freeze after selecting a custom multiple field choice.

TODO

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • Attached Screenshots, Payload Example
  • Unit, Integration Tests
  • Documentation Updates (when adding/changing features)
  • Example Plugin Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

Copy link
Contributor

@glennmatthews glennmatthews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this seems to only address the MultiSelect symptom reported in #3391. What about fixing the Select symptom as well?

on custom field of the type selection
Only one entry can be selected.

Comment on lines 560 to 568

if not required or default_choice is None:
choices = add_blank_choice(choices)

# Set the initial value to the first available choice (if any)
if set_initial and default_choice:
initial = default_choice.value

if self.type == CustomFieldTypeChoices.TYPE_SELECT:
if not required or default_choice is None:
choices = add_blank_choice(choices)
field_class = CSVChoiceField if for_csv_import else forms.ChoiceField
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change feels wrong to me - the form field (as opposed to the filter form field) for both Select and MultiSelect custom fields should have a blank choice, shouldn't it? Can you help me understand why this should be specific to Select fields only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default multi select fields have blanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding it makes blank a choice in the multi select, which was causing error

nautobot/utilities/utils.py Outdated Show resolved Hide resolved
@@ -70,7 +70,7 @@ class CustomFieldJSONFilter(CustomFieldFilterMixin, django_filters.Filter):
"""Custom field single value filter for backwards compatibility"""


class CustomFieldMultiSelectFilter(CustomFieldFilterMixin, django_filters.Filter):
class CustomFieldMultiSelectFilter(CustomFieldFilterMixin, django_filters.MultipleChoiceFilter):
"""Custom field single value filter for backwards compatibility"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the docstring here no longer accurate/relevant? Do we in fact need this to remain a non-multiple-choice filter for some compatibility reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as of now i get this error, Im thinking its a bug
Screenshot 2023-04-13 at 3 30 33 PM

nautobot/extras/filters/customfields.py Outdated Show resolved Hide resolved
nautobot/extras/filters/customfields.py Outdated Show resolved Hide resolved
nautobot/extras/filters/mixins.py Outdated Show resolved Hide resolved
nautobot/extras/tests/test_customfields.py Show resolved Hide resolved
nautobot/extras/forms/mixins.py Outdated Show resolved Hide resolved
nautobot/extras/models/customfields.py Outdated Show resolved Hide resolved
nautobot/extras/filters/mixins.py Outdated Show resolved Hide resolved
nautobot/extras/filters/customfields.py Outdated Show resolved Hide resolved
nautobot/extras/models/customfields.py Outdated Show resolved Hide resolved
@timizuoebideri1 timizuoebideri1 force-pushed the u/timizuoebideri1-3391-cf-multiple_advance_filter branch from 040edaf to 8738527 Compare April 18, 2023 22:09
nautobot/extras/models/customfields.py Outdated Show resolved Hide resolved
nautobot/extras/models/customfields.py Outdated Show resolved Hide resolved
nautobot/extras/tests/test_customfields.py Outdated Show resolved Hide resolved
@timizuoebideri1 timizuoebideri1 changed the base branch from develop to next June 11, 2023 21:10
Copy link
Contributor

@jathanism jathanism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. :shipit:

nautobot/extras/filters/customfields.py Outdated Show resolved Hide resolved
@timizuoebideri1 timizuoebideri1 merged commit d3906b1 into next Jun 15, 2023
21 checks passed
@timizuoebideri1 timizuoebideri1 deleted the u/timizuoebideri1-3391-cf-multiple_advance_filter branch June 15, 2023 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to select multiple entries on (Multiple) selection custom fields in filter
4 participants