Adding filters to dcim.DeviceFilterSet breaks dynamic groups edit form for devices
See original GitHub issueEnvironment
- Python version: 3.7.13 (default, Jun 23 2022, 12:05:54)
- Nautobot version: 1.4.0a1
Steps to Reproduce
- Add a
device_type
filter todcim.filters.DeviceTypeFilterSet
device_type = django_filters.ModelMultipleChoiceFilter(
queryset=DeviceType.objects.all(),
label="Device type (ID)",
)
- Create a dynamic group with content type
dcim.device
- Edit the group and try to click Update (fails with must select a value for device type)
- Select a value for device type and click Update (500 error)
Expected Behavior
Device type should be an optional form field and it should be a multiselect to support ModelMultipleChoiceFilter.
Observed Behavior
Device type is a required field and when populated and form is submitted an exception is raised.
ValidationError at /extras/dynamic-groups/test2/edit/
{'device_type': ['Enter a list of values.']}
Fixed criteria
Dynamic groups form for dcim.device should be updated to support the following proposed filters (staged in branch gas-1982-dcim-device-filters):
device_type
(NaturalKeyOrPKMultipleChoiceFilter
)device_role
(NaturalKeyOrPKMultipleChoiceFilter
)rack
(NaturalKeyOrPKMultipleChoiceFilter
)cluster
(NaturalKeyOrPKMultipleChoiceFilter
)virtual_chassis
(NaturalKeyOrPKMultipleChoiceFilter
)front_ports
(NaturalKeyOrPKMultipleChoiceFilter
)rear_ports
(NaturalKeyOrPKMultipleChoiceFilter
)primary_ip4
(django_filters.ModelMultipleChoiceFilter
)primary_ip6
(django_filters.ModelMultipleChoiceFilter
)parent_bay
(NaturalKeyOrPKMultipleChoiceFilter
)inventory_items
(TreeNodeMultipleChoiceFilter
)has_inventory_items
(RelatedMembershipBooleanFilter
)vc_master_for
(NaturalKeyOrPKMultipleChoiceFilter
)services
(NaturalKeyOrPKMultipleChoiceFilter
)has_services
(RelatedMembershipBooleanFilter
)
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Dynamic Groups - Nautobot Documentation
Dynamic Groups provide a way to organize objects of the same Content Type by matching filters. A Dynamic Group can be used to...
Read more >Add support for Dynamic / arbitrary groups of objects #896
I want to be able to create dynamic groups, So that I can easily see which devices match a specific query further enabling...
Read more >Dynamic membership rules for groups in Azure Active Directory
This article details the properties and syntax to create dynamic membership rules for users or devices. You can set up a rule for...
Read more >Dynamic Groups | ESET PROTECT
Dynamic Groups can be seen as filters based on computer status. One computer may apply for more than one filter and, therefore, be...
Read more >Adding or removing users dynamically from the Groups page
Use the Groups details page to add or remove members dynamically based on a filter.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I built atop Gary’s changeset in my branch gfm-issue-1982. The path I started down was collapsing
MultiMatchModelMultipleChoiceField
functionality back intoDynamicModelMultipleChoiceField
, which I still think is the right direction to take, but we realized there’s a lot of overlap between what I was having to implement and the changes being made in #2348 (especiallyget_filterset_parameter_form_field
) so I think it makes sense to shelve this for the moment and revisit it once that work is complete.Seeing something similar in PR #2849 which adds many of the above filters - the new NaturalKeyOrPkMultipleChoiceFilter filters are OK if omitted from a dynamic group, but if any value is selected for these filters in defining the dynamic group, the values are rejected as invalid:
I’m working on a fix.