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

Custom Field filter doesn't work if UUID is provided #5009

Closed
aj-cruz opened this issue Dec 21, 2023 · 3 comments · Fixed by #5552
Closed

Custom Field filter doesn't work if UUID is provided #5009

aj-cruz opened this issue Dec 21, 2023 · 3 comments · Fixed by #5552
Assignees
Labels
ms type: bug Something isn't working as expected

Comments

@aj-cruz
Copy link

aj-cruz commented Dec 21, 2023

Environment

  • Nautobot version (Docker tag too if applicable): 2.0.6-py3.11 & 2.1.0-py3.11
  • Python version: 3.11.7
  • Database platform, version: Postgres 15.2
  • Middleware(s):

Steps to Reproduce

  1. Create a Custom Field named "Upgrade Group" of type Selection for Content Type dcim.device
  2. Create multiple Custom Field Choices (Group A, Group B)
  3. Edit a device and set the Upgrade Group custom field to Group A
  4. Navigate to https://<host>/dcim/devices/?cf_upgrade_group=<uuid_of_group_a>

Expected Behavior

Filtered device list displays (only devices with Upgrade Group set to "Group A")

Observed Behavior

Zero devices display

Additional Information

Using the name instead of the uuid (https://<host>/dcim/devices/?cf_upgrade_group=Group%20A) works, but when the filter is used in a job like this:

    upgrade_group = ObjectVar(
        label="Upgrade Group",
        description="Device custom field",
        model=CustomFieldChoice,
        required=False,
        query_params = {
            "custom_field": "upgrade_group",
        }
    )

    devices = ObjectVar(
        label="Devices",
        description="Optional Device filter",
        model=Device,
        required=False,
        query_params = {
            "device_type": "$device_type",
            "location": "$location",
            "cf_upgrade_group": "$upgrade_group",
        }
    )

The UUID not the name gets passed to the API. I see this in the compose logs:
nginx | 172.21.0.229 - - [21/Dec/2023:09:06:37 +0000] "GET /api/dcim/devices/?q=&limit=50&offset=0&depth=0&cf_upgrade_group=c639def9-2784-4f32-9637-3f4aa3cfbcaa HTTP/2.0" 200 52 "https://192.168.253.20/extras/jobs/e6cdbd6b-977a-42a1-9d17-13c9dd7fbbf3/run/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0" "-"
and the device list in the job form is empty (no results found)

@aj-cruz aj-cruz added triage This issue is new and has not been reviewed. type: bug Something isn't working as expected labels Dec 21, 2023
@gsnider2195
Copy link
Contributor

Thanks for the report. It looks like we'll need to change the default filters in nautobot.extras.filters.CustomFieldModelFilterSetMixin to use NaturalKeyOrPKMultipleChoiceFilter for CustomFieldTypeChoices.TYPE_MULTISELECT and CustomFieldTypeChoices.TYPE_SELECT

@gsnider2195 gsnider2195 removed the triage This issue is new and has not been reviewed. label Jan 2, 2024
@david-kn
Copy link
Contributor

Hi there, I'd be glad to have this implemented as well. We also noticed the inability to search custom fields by UUID but it would be very useful for us! e.g. /ipam/prefixes/?cf_my_field=c1442670-c8bf-4604-ac91-86436baf661d instead of just representing string value.

@lampwins lampwins added the ms label Mar 20, 2024
@lampwins
Copy link
Member

lampwins commented Apr 1, 2024

Needed in 1.6 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ms type: bug Something isn't working as expected
Projects
No open projects
Status: To Groom
Development

Successfully merging a pull request may close this issue.

5 participants