nb.ipam.ip_addresses.filter() does not work for IPv6 addresses on 2.2.4 #1377

Closed
opened 2025-12-29 16:31:54 +01:00 by adam · 4 comments
Owner

Originally created by @oysteingy on GitHub (Nov 1, 2017).

Issue type

[ ] Feature request
[X ] Bug report
[ ] Documentation

Environment

  • Python version: 2.7.13
  • NetBox version: 2.2.4

Looks like the works in #1620 broke lookup for IPv6 addresses, I can no longer search for IPv6 addresses using the API.

I have some IPv6 addresses in the database:

(Pdb) len(nb.ipam.ip_addresses.filter(family=6))
32

Try to lookup the first address

(Pdb) nb.ipam.ip_addresses.filter(nb.ipam.ip_addresses.filter(family=6)[0])
[]

Neither does lookup on "shortened" IPv6 addresses work like #1620 fixed for IPv4.

The exact same commands works on my 2.2.2 installation, and I see the same results for the web frontend as well. I can only reproduce this for IPaddresses, prefixes works as expected.

Originally created by @oysteingy on GitHub (Nov 1, 2017). ### 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 --> ### Environment * Python version: 2.7.13 * NetBox version: 2.2.4 Looks like the works in #1620 broke lookup for IPv6 addresses, I can no longer search for IPv6 addresses using the API. I have some IPv6 addresses in the database: ```python (Pdb) len(nb.ipam.ip_addresses.filter(family=6)) 32 ``` Try to lookup the first address ```python (Pdb) nb.ipam.ip_addresses.filter(nb.ipam.ip_addresses.filter(family=6)[0]) [] ``` Neither does lookup on "shortened" IPv6 addresses work like #1620 fixed for IPv4. The exact same commands works on my 2.2.2 installation, and I see the same results for the web frontend as well. I can only reproduce this for IPaddresses, prefixes works as expected.
adam closed this issue 2025-12-29 16:31:54 +01:00
Author
Owner

@oysteingy commented on GitHub (Nov 2, 2017):

I reversed commit #515645b manually- IPv6 lookup works as expected now.

(Pdb) len(nb.ipam.ip_addresses.filter(nb.ipam.ip_addresses.filter(family=6)[0]))
1
@oysteingy commented on GitHub (Nov 2, 2017): I reversed commit #515645b manually- IPv6 lookup works as expected now. ```python (Pdb) len(nb.ipam.ip_addresses.filter(nb.ipam.ip_addresses.filter(family=6)[0])) 1 ```
Author
Owner

@jeremystretch commented on GitHub (Nov 2, 2017):

I'm not sure what you're doing here; nb.ipam.ip_addresses.filter() isn't provided by NetBox. A queryset for IP address is formed as:

IPAddres.objects.all()

As far as I can tell, all the filters work as intended:

>>> IPAddress.objects.filter(family=6).count()
592
>>> IPAddress.objects.filter(address__istartswith='2001:db8').count()
4
@jeremystretch commented on GitHub (Nov 2, 2017): I'm not sure what you're doing here; `nb.ipam.ip_addresses.filter()` isn't provided by NetBox. A queryset for IP address is formed as: ``` IPAddres.objects.all() ``` As far as I can tell, all the filters work as intended: ``` >>> IPAddress.objects.filter(family=6).count() 592 >>> IPAddress.objects.filter(address__istartswith='2001:db8').count() 4 ```
Author
Owner

@jeremystretch commented on GitHub (Nov 2, 2017):

It occurs to me you're using the pynetbox API client. Please open an issue against that project if you believe you've found a bug.

@jeremystretch commented on GitHub (Nov 2, 2017): It occurs to me you're using the [pynetbox](https://github.com/digitalocean/pynetbox) API client. Please open an issue against that project if you believe you've found a bug.
Author
Owner

@oysteingy commented on GitHub (Dec 5, 2017):

Hi,

I'm bumping this again, I do not believe that the problem is related to pynetbox but with the Netbox RESTAPI. Upon upgrade 2.2.4 => 2.2.6, my manual backport of #1620 was overwritten.

This looks fine with nbshell

# python3 manage.py nbshell                                                                                                                                                                                                                                                                        
### NetBox interactive shell (netbox)                                                                                                                                                                                                                                                                       
### Python 3.4.5 | Django 1.11.8 | NetBox 2.2.6                                                                                                                                                                                                                                                                              
### lsmodels() will show available models. Use help(<model>) for more info.                                                                                                                                                                                                                                                  
>>> IPAddress.objects.filter(address="2a12:2b48:0:1001::1/127")                                                                                                                                                                                                                                                              
<QuerySet [<IPAddress: 2a12:2b48:0:1001::1/127>]>                

Same query with the API returns nothing:
curl -H "Authorization: Token $TOKEN" -H "Accept: application/json; indent=4" "http://netbox/netbox/api/ipam/ip-addresses/?q=2a12:2b48:0:1001::1/127"
{
"count": 0,

}

Looking up the prefix works fine with the API:
curl -H "Authorization: Token $TOKEN " -H "Accept: application/json; indent=4" "http://netbox/netbox/api/ipam/prefixes/?q=2a12:2b48:0:1001::1/127"
{
"count": 2,
}

By looking at the commit from #1620, this looks reasonable, istartswith seems not to work particularly well with IPv6

 >>> IPAddress.objects.filter(address__istartswith='2a12:2b48:0:1001::1/127')                                                                                                                                                                                                                                                 
<QuerySet []>       
Trying to lookup with address__net_contains_or_equals which is used for prefix works fine:
>>> IPAddress.objects.filter(address__net_contains_or_equals="2a12:2b48:0:1001::1/127")                                                                                                                                                                                                                                      
<QuerySet [<IPAddress: 2a12:2b48:0:1001::1/127>]>     
@oysteingy commented on GitHub (Dec 5, 2017): Hi, I'm bumping this again, I do not believe that the problem is related to pynetbox but with the Netbox RESTAPI. Upon upgrade 2.2.4 => 2.2.6, my manual backport of #1620 was overwritten. This looks fine with nbshell ```python # python3 manage.py nbshell ### NetBox interactive shell (netbox) ### Python 3.4.5 | Django 1.11.8 | NetBox 2.2.6 ### lsmodels() will show available models. Use help(<model>) for more info. >>> IPAddress.objects.filter(address="2a12:2b48:0:1001::1/127") <QuerySet [<IPAddress: 2a12:2b48:0:1001::1/127>]> ``` Same query with the API returns nothing: curl -H "Authorization: Token $TOKEN" -H "Accept: application/json; indent=4" "http://netbox/netbox/api/ipam/ip-addresses/?q=2a12:2b48:0:1001::1/127" { "count": 0, } Looking up the prefix works fine with the API: curl -H "Authorization: Token $TOKEN " -H "Accept: application/json; indent=4" "http://netbox/netbox/api/ipam/prefixes/?q=2a12:2b48:0:1001::1/127" { "count": 2, } By looking at the commit from #1620, this looks reasonable, istartswith seems not to work particularly well with IPv6 ```python >>> IPAddress.objects.filter(address__istartswith='2a12:2b48:0:1001::1/127') <QuerySet []> ``` ```python Trying to lookup with address__net_contains_or_equals which is used for prefix works fine: >>> IPAddress.objects.filter(address__net_contains_or_equals="2a12:2b48:0:1001::1/127") <QuerySet [<IPAddress: 2a12:2b48:0:1001::1/127>]> ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1377