New search feature: vid doesn't match when queried #7382

Closed
opened 2025-12-29 20:22:40 +01:00 by adam · 8 comments
Owner

Originally created by @cs-1 on GitHub (Dec 19, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.4.1

Python version

3.8

Steps to Reproduce

  1. Create a VLAN with vid 1234.
  2. Search for "1234" in search field.

Expected Behavior

A search for "1234" should yield the created VLAN in the results.

Observed Behavior

VLAN 1234 isn't found.

I've looked at the new search mechanism in > v3.4.0 and at least in netbox/netbox/ipam/search.py I can find

@register_search
class VLANIndex(SearchIndex):
    model = models.VLAN
    fields = (
        ('name', 100),
        ('vid', 100),
        ('description', 500),
        ('comments', 5000),
    )

which means that vid should be used as "Primary human identifier" to find the VLAN. But it reproducibly doesn't work.

Originally created by @cs-1 on GitHub (Dec 19, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.4.1 ### Python version 3.8 ### Steps to Reproduce 1. Create a VLAN with vid 1234. 2. Search for "1234" in search field. ### Expected Behavior A search for "1234" should yield the created VLAN in the results. ### Observed Behavior VLAN 1234 isn't found. I've looked at the new search mechanism in > v3.4.0 and at least in [netbox/netbox/ipam/search.py](https://github.com/netbox-community/netbox/blob/93685d92a40de88688b24ab7150d549275b236e9/netbox/ipam/search.py) I can find ```python @register_search class VLANIndex(SearchIndex): model = models.VLAN fields = ( ('name', 100), ('vid', 100), ('description', 500), ('comments', 5000), ) ``` which means that `vid` should be used as "Primary human identifier" to find the VLAN. But it reproducibly doesn't work.
adam added the type: bugstatus: accepted labels 2025-12-29 20:22:40 +01:00
adam closed this issue 2025-12-29 20:22:40 +01:00
Author
Owner

@cs-1 commented on GitHub (Dec 19, 2022):

P. S.: Changing the Lookup from "Partial match" to "Exact match" will give me a result for "1234". Is this a typing issue (string vs. integer) in partial matching?

@cs-1 commented on GitHub (Dec 19, 2022): P. S.: Changing the Lookup from "Partial match" to "Exact match" will give me a result for "1234". Is this a typing issue (string vs. integer) in partial matching?
Author
Owner

@kkthxbye-code commented on GitHub (Dec 19, 2022):

Is this a typing issue (string vs. integer) in partial matching?

Looking at the code, it's an intended choice.

3675ad2539/netbox/netbox/search/backends.py (L102-L104)

I'm guessing the idea is that it would be annoying searching for e.g. VLAN 20 and then getting all VLAN's with 20 somewhere in the number string. @jeremystretch would have to weigh in here though.

@kkthxbye-code commented on GitHub (Dec 19, 2022): > Is this a typing issue (string vs. integer) in partial matching? Looking at the code, it's an intended choice. https://github.com/netbox-community/netbox/blob/3675ad2539400038af6797140ddca3679b8bca30/netbox/netbox/search/backends.py#L102-L104 I'm guessing the idea is that it would be annoying searching for e.g. VLAN 20 and then getting all VLAN's with 20 somewhere in the number string. @jeremystretch would have to weigh in here though.
Author
Owner

@cs-1 commented on GitHub (Dec 19, 2022):

It would be helpful to have partial searches for VLAN IDs as well (as in v3.3.10 and earlier). The comment # Partial matches are valid only on string values leads me to think that this is a workaround for "icontains" or "contains" not working with integers but it definitely does:

### NetBox interactive shell (XXXX)
### Python 3.8.10 | Django 4.1.4 | NetBox 3.4.1
### lsmodels() will show available models. Use help(<model>) for more info.
>>> VLAN.objects.filter(vid__icontains=113)
<VLANQuerySet [<VLAN: XXXXXXXXXX (1113)>, <VLAN: XXXXXXXXXX (1130)>, <VLAN: XXXXXXXXXX (1131)>]>
>>>

It's definitely possible that I misunderstand the comment.

@cs-1 commented on GitHub (Dec 19, 2022): It would be helpful to have partial searches for VLAN IDs as well (as in v3.3.10 and earlier). The comment `# Partial matches are valid only on string values` leads me to think that this is a workaround for "icontains" or "contains" not working with integers but it definitely does: ```python ### NetBox interactive shell (XXXX) ### Python 3.8.10 | Django 4.1.4 | NetBox 3.4.1 ### lsmodels() will show available models. Use help(<model>) for more info. >>> VLAN.objects.filter(vid__icontains=113) <VLANQuerySet [<VLAN: XXXXXXXXXX (1113)>, <VLAN: XXXXXXXXXX (1130)>, <VLAN: XXXXXXXXXX (1131)>]> >>> ``` It's definitely possible that I misunderstand the comment.
Author
Owner

@PieterL75 commented on GitHub (Dec 20, 2022):

partial vlan id's are something that I use.. regex would even be better. I would like to search for a free vlan starting with 301 (so 3010-3019), that whould work with '301' and it would be awesome to work with regex 300[0-9]

@PieterL75 commented on GitHub (Dec 20, 2022): partial vlan id's are something that I use.. regex would even be better. I would like to search for a free vlan starting with 301 (so 3010-3019), that whould work with '301' and it would be awesome to work with regex 300[0-9]
Author
Owner

@jeremystretch commented on GitHub (Dec 22, 2022):

I'm guessing the idea is that it would be annoying searching for e.g. VLAN 20 and then getting all VLAN's with 20 somewhere in the number string.

Correct; that was the design intent. Imagine trying to search for VID 1 and receiving results for all VIDs containing a 1.

regex would even be better

I agree regular expressions are best suited for this use case. Incidentally, regex search should work for this, but accommodations for the existing logic were overlooked during the implementation of #11090. It's an easy fix.

@jeremystretch commented on GitHub (Dec 22, 2022): > I'm guessing the idea is that it would be annoying searching for e.g. VLAN 20 and then getting all VLAN's with 20 somewhere in the number string. Correct; that was the design intent. Imagine trying to search for VID 1 and receiving results for all VIDs containing a 1. > regex would even be better I agree regular expressions are best suited for this use case. Incidentally, regex search _should_ work for this, but accommodations for the existing logic were overlooked during the implementation of #11090. It's an easy fix.
Author
Owner

@cs-1 commented on GitHub (Dec 22, 2022):

Correct; that was the design intent. Imagine trying to search for VID 1 and receiving results for all VIDs containing a 1.

But using the "Exact match" option will prevent this and "Partial match" not doing what it says it does for vids is counterintuitive. I agree with @PieterL75, we use "Partial match" regularly to get tons of results because we actually use "Partial match" as an intended feature. Partial match was the default search behaviour in NetBox v3.3.x and earlier so we've been using it on a day-to-day basis for VLAN searches being fully aware that it'll produce tons of results when only entering partial vids.

I agree regular expressions are best suited for this use case. Incidentally, regex search should work for this, but accommodations for the existing logic were overlooked during the implementation of #11090. It's an easy fix.

Regex would be great, too. However, my request would be to enable "Partial match" for vids because the other use case is already covered by the "Exact match" option.

@cs-1 commented on GitHub (Dec 22, 2022): > Correct; that was the design intent. Imagine trying to search for VID 1 and receiving results for all VIDs containing a 1. But using the "Exact match" option will prevent this and "Partial match" not doing what it says it does for vids is counterintuitive. I agree with @PieterL75, we use "Partial match" regularly to get tons of results because we actually use "Partial match" as an intended feature. Partial match was the default search behaviour in NetBox v3.3.x and earlier so we've been using it on a day-to-day basis for VLAN searches being fully aware that it'll produce tons of results when only entering partial vids. > I agree regular expressions are best suited for this use case. Incidentally, regex search _should_ work for this, but accommodations for the existing logic were overlooked during the implementation of #11090. It's an easy fix. Regex would be great, too. However, my request would be to enable "Partial match" for vids because the other use case is already covered by the "Exact match" option.
Author
Owner

@jeremystretch commented on GitHub (Dec 22, 2022):

Ok, we'll try enabling partial matching and see how it works out. Worst case, we can have the option of falling back to regex for more intelligent matching.

Partial match was the default search behaviour in NetBox v3.3.x and earlier

This is incorrect. The legacy search function used a variety of different lookups, each specific to the particular field being queried on each model. VLANs, for instance, would only match on complete VID values, just as the new global search does currently.

@jeremystretch commented on GitHub (Dec 22, 2022): Ok, we'll try enabling partial matching and see how it works out. Worst case, we can have the option of falling back to regex for more intelligent matching. > Partial match was the default search behaviour in NetBox v3.3.x and earlier This is incorrect. The legacy search function used a variety of different lookups, each specific to the particular field being queried on each model. VLANs, for instance, would only match on complete VID values, just as the new global search does currently.
Author
Owner

@cs-1 commented on GitHub (Dec 22, 2022):

Ok, we'll try enabling partial matching and see how it works out. Worst case, we can have the option of falling back to regex for more intelligent matching.

Thanks, it's highly appreciated!

This is incorrect. The legacy search function used a variety of different lookups, each specific to the particular field being queried on each model. VLANs, for instance, would only match on complete VID values, just as the new global search does currently.

Huh! You're right! I mixed vids up with our internal site numbers that are part of the "name" field (a string field which is partially matched). I'm terribly sorry. I now realise that what got us stumbling was the fact that you didn't get any match for VLAN 1234 in v3.4.x when entering "1234" in the search field when doing a "Partial match" search but only when doing an "Exact match" search. Sorry for the mixup.

@cs-1 commented on GitHub (Dec 22, 2022): > Ok, we'll try enabling partial matching and see how it works out. Worst case, we can have the option of falling back to regex for more intelligent matching. Thanks, it's highly appreciated! > This is incorrect. The legacy search function used a variety of different lookups, each specific to the particular field being queried on each model. VLANs, for instance, would only match on complete VID values, just as the new global search does currently. Huh! You're right! I mixed vids up with our internal site numbers that are part of the "name" field (a string field which is partially matched). I'm terribly sorry. I now realise that what got us stumbling was the fact that you didn't get any match for VLAN 1234 in v3.4.x when entering "1234" in the search field when doing a "Partial match" search but only when doing an "Exact match" search. Sorry for the mixup.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7382