question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding filters to dcim.DeviceFilterSet breaks dynamic groups edit form for devices

See original GitHub issue

Environment

  • Python version: 3.7.13 (default, Jun 23 2022, 12:05:54)
  • Nautobot version: 1.4.0a1

Steps to Reproduce

  1. Add a device_type filter to dcim.filters.DeviceTypeFilterSet
    device_type = django_filters.ModelMultipleChoiceFilter(
        queryset=DeviceType.objects.all(),
        label="Device type (ID)",
    )
  1. Create a dynamic group with content type dcim.device
  2. Edit the group and try to click Update (fails with must select a value for device type)
  3. 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:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
glennmatthewscommented, Sep 20, 2022

I built atop Gary’s changeset in my branch gfm-issue-1982. The path I started down was collapsing MultiMatchModelMultipleChoiceField functionality back into DynamicModelMultipleChoiceField, 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 (especially get_filterset_parameter_form_field) so I think it makes sense to shelve this for the moment and revisit it once that work is complete.

0reactions
glennmatthewscommented, Dec 8, 2022

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:

image

image

I’m working on a fix.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found