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

Incorrect tag search - illusory duplicates returned #1692

Closed
david-kn opened this issue Apr 25, 2022 · 4 comments · Fixed by #1703
Closed

Incorrect tag search - illusory duplicates returned #1692

david-kn opened this issue Apr 25, 2022 · 4 comments · Fixed by #1703
Assignees
Labels
good first issue Great issues for newcomers! type: bug Something isn't working as expected

Comments

@david-kn
Copy link
Contributor

  • Python version: 3.10
  • Nautobot version: 1.3.2

Steps to Reproduce

  1. Search for an existing tag (in my case substring, e.g. exclude):
  • either in Organization-> Tags page or
  • when adding tag for any other object (see attached images)

Expected Behavior

Only existing (unique) tag(s) should be returned.

Observed Behavior

There are too many returned tags (not unique) that are duplicate (as for each model would exist individual tag with the same name). The number of returned duplicate tags correspond with a number of attached models to a given tag (in my case 35)

image
image

btw. So far, I noticed this only for Tags but not for Statuses which can also be connected with multiple models.

@ubajze
Copy link
Contributor

ubajze commented Apr 26, 2022

@david-kn I tried to reproduce the issue but I was not able to do it. I tried to add more tags through the UI.

I am wondering what you get if you run the following in nbshell:

>>> for tag in Tag.objects.filter(name="scan_exclude"):
...  print(tag.pk, tag.content_types.all())

@glennmatthews
Copy link
Contributor

I can confirm this issue. It does not happen in the base Tags list (un-searched), but does appear when a search is issued.

@glennmatthews glennmatthews added type: bug Something isn't working as expected status: accepted labels Apr 26, 2022
@glennmatthews
Copy link
Contributor

The below diff appears to fix the issue:

diff --git a/nautobot/extras/filters.py b/nautobot/extras/filters.py
index 48a0a4550..338a858a9 100644
--- a/nautobot/extras/filters.py
+++ b/nautobot/extras/filters.py
@@ -977,7 +977,7 @@ class TagFilterSet(NautobotFilterSet):
             return queryset
         return queryset.filter(
             Q(name__icontains=value) | Q(slug__icontains=value) | Q(content_types__model__icontains=value)
-        )
+        ).distinct()
 
 
 #

@glennmatthews glennmatthews added the good first issue Great issues for newcomers! label Apr 26, 2022
@david-kn
Copy link
Contributor Author

david-kn commented Apr 26, 2022

Thanks Glen for confirmation :-) To filter and show only distinct values was my inner guess as well.

btw. Isn't such a fix a good candidate also for 1.3.3 release sometimes in a near future as well? :-)
We won't upgrade to 1.3.2 yet because this behavior would be very confusing for many users.

@jathanism jathanism self-assigned this Apr 26, 2022
bryanculver added a commit that referenced this issue Apr 27, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Great issues for newcomers! type: bug Something isn't working as expected
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants