Fix DynamicGroup Serialization Bug #4178
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes: #DNE
What's Changed
Worked with @lampwins to reproduce this bug.
TLDR: When a Dynamic Group is being saved, there is an edge case where a Filter Form and a FilterSet Form are not identical. A way to reproduce this is with: https://github.com/nautobot/nautobot/tree/u/bryanculver-dg-bug and creating the necessary relationship to filter on it. What happened is the nested filter through the relationship and ultimately is filtering on the
name
of an FK, the FilterSet Form expects inputs to be a list of strings (it's a MultiValueCharFilter after all). But for UX we want to have a selection of names of object instances. We can do this by using theto_field_name
and processing accordingly. We have logic in Dynamic Groups that does this if the FilterSetForm filed is of the right type. The FilterForm is helping us to this today, but the FilterSetForms need some work to be returning/use the smarter Form field types.This fix allows to use the FilterForm field first if it's available and falls back if it's not.
Special handling had to be done for Tags because our Tag filter form field isn't a ModelMultipleChoiceField; the FilterSetForm field before was using a ModelMultipleChoiceField.
I'm open to ideas on how to write a test for this which doesn't require a bunch of complex setup like in the branch referenced above.
TODO