Custom field choice filtering matches multiple choices #1248

Closed
opened 2025-12-29 16:30:35 +01:00 by adam · 11 comments
Owner

Originally created by @jvanderaa on GitHub (Sep 19, 2017).

Originally assigned to: @jeremystretch on GitHub.

Issue type

[ ] Feature request
[x] Bug report
[ ] Documentation

Environment

  • Python version: Python 3.5.2
  • NetBox version: 2.1.4 (updated - previously wrote down wrong version of 2.0.5)

DCIM Custom Field Search - Returning Wrong Info

I setup a custom field to maintain our support contract information for each of the devices. I originally had 3 choices setup. I then got a bigger list of contracts and am now up to 13. When I search for devices in a field that I state has one coverage, devices with "Needs Coverage" show up. I click into the device and it has the custom field setup properly. When checking the API, it also reports the proper field back. However when I search for devices of each field type, they are showing up in the wrong place.

####Steps to Reproduce:

  1. Click on Devices -> Devices
  2. Go down the right hand column and select the drop down of the custom field (drop down field)
  3. Search for devices, and devices with that custom field setting show up.
Originally created by @jvanderaa on GitHub (Sep 19, 2017). Originally assigned to: @jeremystretch on GitHub. <!-- Before opening a new issue, please search through the existing issues to see if your topic has already been addressed. Note that you may need to remove the "is:open" filter from the search bar to include closed issues. Check the appropriate type for your issue below by placing an x between the brackets. If none of the below apply, please raise your issue for discussion on our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please note that issues which do not fall under any of the below categories will be closed. ---> ### Issue type [ ] Feature request <!-- Requesting the implementation of a new feature --> [x] Bug report <!-- Reporting unexpected or erroneous behavior --> [ ] Documentation <!-- Proposing a modification to the documentation --> <!-- Please describe the environment in which you are running NetBox. (Be sure to verify that you are running the latest stable release of NetBox before submitting a bug report.) --> ### Environment * Python version: Python 3.5.2 * NetBox version: 2.1.4 (updated - previously wrote down wrong version of 2.0.5) <!-- BUG REPORTS must include: FEATURE REQUESTS must include: * A detailed description of the proposed functionality * A use case for the new feature * A rough description of any necessary changes to the database schema * Any relevant third-party libraries which would be needed --> ### DCIM Custom Field Search - Returning Wrong Info I setup a custom field to maintain our support contract information for each of the devices. I originally had 3 choices setup. I then got a bigger list of contracts and am now up to 13. When I search for devices in a field that I state has one coverage, devices with "Needs Coverage" show up. I click into the device and it has the custom field setup properly. When checking the API, it also reports the proper field back. However when I search for devices of each field type, they are showing up in the wrong place. ####Steps to Reproduce: 1) Click on Devices -> Devices 2) Go down the right hand column and select the drop down of the custom field (drop down field) 3) Search for devices, and devices with that custom field setting show up.
adam added the type: bug label 2025-12-29 16:30:35 +01:00
adam closed this issue 2025-12-29 16:30:35 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 19, 2017):

Please upgrade to the most recent release of NetBox (v2.1.4) to see if that resolves your issue.

@jeremystretch commented on GitHub (Sep 19, 2017): Please upgrade to the most recent release of NetBox (v2.1.4) to see if that resolves your issue.
Author
Owner

@jvanderaa commented on GitHub (Sep 19, 2017):

Sorry Jeremy, I am at 2.1.4. Something got in my mind that I was a little ways back.
(v2.1.4)

@jvanderaa commented on GitHub (Sep 19, 2017): Sorry Jeremy, I am at 2.1.4. Something got in my mind that I was a little ways back. (v2.1.4)
Author
Owner

@jeremystretch commented on GitHub (Sep 22, 2017):

@vanderaaj Could you please extend the steps needed to recreate this? Be sure to outline the process of creating the custom field first.

@jeremystretch commented on GitHub (Sep 22, 2017): @vanderaaj Could you please extend the steps needed to recreate this? Be sure to outline the process of creating the custom field first.
Author
Owner

@jvanderaa commented on GitHub (Sep 27, 2017):

Do my best.

  1. Created DCIM custom field on the Django admin page as a field selection custom field. I believe that I did that with 2.1.4
  2. Added 3 fields to select (I thought there were only 3 service contracts)
  3. I added a few devices to have the service contract

Then I found about 10 more service contracts
4) Went back into the Django admin console and went to the custom field
5) Added the additional 10 service contracts to the field
6) Created script to change the service contract field based on a spreadsheet with the contract information on it
7) The fields that are showing up duplicate are "Not Covered" and "Product name that starts with N.."

  • The remaining contract fields all start with a custom number
@jvanderaa commented on GitHub (Sep 27, 2017): Do my best. 1) Created DCIM custom field on the Django admin page as a field selection custom field. I believe that I did that with 2.1.4 2) Added 3 fields to select (I thought there were only 3 service contracts) 3) I added a few devices to have the service contract Then I found about 10 more service contracts 4) Went back into the Django admin console and went to the custom field 5) Added the additional 10 service contracts to the field 6) Created script to change the service contract field based on a spreadsheet with the contract information on it 7) The fields that are showing up duplicate are "Not Covered" and "Product name that starts with N.." - The remaining contract fields all start with a custom number
Author
Owner

@jeremystretch commented on GitHub (Oct 16, 2017):

@vanderaaj You'll need to provide specific values for every field in the reproduction. You'll also need to provide the exact script that you ran; otherwise, we have no idea what was modified.

@jeremystretch commented on GitHub (Oct 16, 2017): @vanderaaj You'll need to provide specific values for every field in the reproduction. You'll also need to provide the exact script that you ran; otherwise, we have no idea what was modified.
Author
Owner

@jvanderaa commented on GitHub (Oct 19, 2017):

@jeremystretch makes perfect sense to me about wanting the full data, is there a method to get those communicated that isn't all over a Github public page? With this being our contract information, probably best to not have those contract numbers showing up.

I'm almost thinking that it may have been something with adding in additional contracts after adding data. Or else, just an input error on my part. I'm all for getting the data if it will help the community in the future. But if it is just to try to fix one individual user issue, I'm good with deleting and recreating the custom field. I've automated the process of getting each device into that field, so that isn't much work.

@jvanderaa commented on GitHub (Oct 19, 2017): @jeremystretch makes perfect sense to me about wanting the full data, is there a method to get those communicated that isn't all over a Github public page? With this being our contract information, probably best to not have those contract numbers showing up. I'm almost thinking that it may have been something with adding in additional contracts after adding data. Or else, just an input error on my part. I'm all for getting the data if it will help the community in the future. But if it is just to try to fix one individual user issue, I'm good with deleting and recreating the custom field. I've automated the process of getting each device into that field, so that isn't much work.
Author
Owner

@jeremystretch commented on GitHub (Oct 19, 2017):

@vanderaaj

is there a method to get those communicated that isn't all over a Github public page?

All development activity is tracked publicly. You'll need to detail the steps needed to recreate the bug using sanitized or fabricated data. Starting up a separate instance of NetBox running a fresh installation is a good idea.

@jeremystretch commented on GitHub (Oct 19, 2017): @vanderaaj > is there a method to get those communicated that isn't all over a Github public page? All development activity is tracked publicly. You'll need to detail the steps needed to recreate the bug using sanitized or fabricated data. Starting up a separate instance of NetBox running a fresh installation is a good idea.
Author
Owner

@jvanderaa commented on GitHub (Oct 19, 2017):

All good on the public dev. I thought a previous comment wanted the real live data. One more attempt...

  1. Go to User Account on top right and select drop down to Admin
  2. Click Add under Custom Fields
  3. Create Custom Field as follows:
    a. Object: "dcim > device"
    b. Type: "Selection"
    c. Name: "support_contract"
    d. Label: "Support Contract"
    e. Description: "Support Contract Information"
    f. Required: Unchecked
    g. Is filterable: Checked
    h. Default: Blank
    i. Weight: "100"

Custom Field Choices Set
Value: "NationalCoverage"
Value: "44223355: 8x5xNBD"
Value: "44223355: 24x7x4"

Set approximately 12 devices to the 3rd value, then I found more contracts.

Followed the same process to get into the dcim custom field.

Then added the following options
Value: "202438275: 8x5xNBD"
Value: "202438705: 8x5xNBD"
Value: "202531453: 8x5xNBD"
Value: "84284102: EMER"
Value: "93583721: P2E"
Value: "94283751: EMER"
Value: "94678217: PEA"
Value: "Needs Coverage"

Then I had a CSV file with device, contract and used the API to assign a contract to the device.
Then some devices that have the NationalCoverage contract show up in a query for
devices in Needs Coverage. When going into the device, it shows properly. The
search page just displays incorrectly.

@jvanderaa commented on GitHub (Oct 19, 2017): All good on the public dev. I thought a previous comment wanted the real live data. One more attempt... 1. Go to User Account on top right and select drop down to *Admin* 2. Click *Add* under **Custom Fields** 3. Create Custom Field as follows: a. Object: "dcim > device" b. Type: "Selection" c. Name: "support_contract" d. Label: "Support Contract" e. Description: "Support Contract Information" f. Required: *Unchecked* g. Is filterable: *Checked* h. Default: *Blank* i. Weight: "100" Custom Field Choices Set Value: "NationalCoverage" Value: "44223355: 8x5xNBD" Value: "44223355: 24x7x4" Set approximately 12 devices to the 3rd value, then I found more contracts. Followed the same process to get into the dcim custom field. Then added the following options Value: "202438275: 8x5xNBD" Value: "202438705: 8x5xNBD" Value: "202531453: 8x5xNBD" Value: "84284102: EMER" Value: "93583721: P2E" Value: "94283751: EMER" Value: "94678217: PEA" Value: "Needs Coverage" Then I had a CSV file with device, contract and used the API to assign a contract to the device. Then some devices that have the **NationalCoverage** contract show up in a query for devices in **Needs Coverage**. When going into the device, it shows properly. The search page just displays incorrectly.
Author
Owner

@jeremystretch commented on GitHub (Oct 20, 2017):

When going into the device, it shows properly. The search page just displays incorrectly.

Please provide the query you're using to search.

@jeremystretch commented on GitHub (Oct 20, 2017): > When going into the device, it shows properly. The search page just displays incorrectly. Please provide the query you're using to search.
Author
Owner

@jvanderaa commented on GitHub (Oct 20, 2017):

Devices -> Devices, Scroll down the right hand search filter to Support Contract custom field drop down. Selecting NationalCoverage and then devices with Needs Coverage show up in the search.

@jvanderaa commented on GitHub (Oct 20, 2017): **Devices** -> **Devices**, Scroll down the right hand search filter to Support Contract custom field drop down. Selecting **NationalCoverage** and then devices with **Needs Coverage** show up in the search.
Author
Owner

@jeremystretch commented on GitHub (Oct 20, 2017):

I think I know what's happening. The PK for the "NationalCoverage" option is 1, and the PK for the "Needs Coverage" option is 11. The query is filtering on ?cf_support_contract=1, which is being evaluated as:

custom_field_values__serialized_value__icontains=1

This matches both serialized values 1 and 11. We need to modify the filter to only match on exact values for select fields.

@jeremystretch commented on GitHub (Oct 20, 2017): I think I know what's happening. The PK for the "NationalCoverage" option is 1, and the PK for the "Needs Coverage" option is 11. The query is filtering on `?cf_support_contract=1`, which is being evaluated as: ``` custom_field_values__serialized_value__icontains=1 ``` This matches both serialized values 1 and 11. We need to modify the filter to only match on exact values for select fields.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1248