Unable to get available prefixes from unsaved Prefix object #4905

Closed
opened 2025-12-29 19:21:59 +01:00 by adam · 0 comments
Owner

Originally created by @nniehoff on GitHub (May 13, 2021).

NetBox version

v2.11.3

Python version

3.8

Steps to Reproduce

  1. Run python netbox/manage.py nbshell
  2. Run the following:
from ipam.models import Prefix
Prefix(prefix="10.0.0.0/8").get_available_prefixes()

If you get the prefix object from the db and call the function everything works as expected:

from ipam.models import Prefix
Prefix(prefix="10.0.0.0/8").save()
Prefix.objects.get(prefix="10.0.0.0/8").get_available_prefixes()
IPSet(['10.0.0.0/8'])

Expected Behavior

IPSet(['10.0.0.0/8'])

Observed Behavior

Traceback (most recent call last):
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 125, in str_to_int
    return _struct.unpack('>I', _inet_pton(AF_INET, addr))[0]
OSError: illegal IP address string passed to inet_pton

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 311, in __init__
    self._value = self._module.str_to_int(addr, flags)
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 129, in str_to_int
    raise AddrFormatError('%r is not a valid IPv4 address string!' % (addr,))
netaddr.core.AddrFormatError: '.' is not a valid IPv4 address string!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 799, in parse_ip_network
    ip = IPAddress(val1, module.version, flags=INET_PTON)
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 313, in __init__
    raise AddrFormatError('base address %r is not IPv%d'
netaddr.core.AddrFormatError: base address '.' is not IPv4

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 263, in expand_partial_address
    tokens = ['%d' % int(o) for o in addr.split('.')]
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 263, in <listcomp>
    tokens = ['%d' % int(o) for o in addr.split('.')]
ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 942, in __init__
    value, prefixlen = parse_ip_network(module, addr,
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 803, in parse_ip_network
    expanded_addr = _ipv4.expand_partial_address(val1)
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 267, in expand_partial_address
    raise error
netaddr.core.AddrFormatError: invalid partial IPv4 address: '.'!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/opt/netbox-2.11.3/netbox/ipam/models/ip.py", line 415, in get_available_prefixes
    prefix = netaddr.IPSet(self.prefix)
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/sets.py", line 121, in __init__
    for cidr in cidr_merge(mergeable):
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 1600, in cidr_merge
    net = IPNetwork(ip)
  File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 953, in __init__
    raise AddrFormatError('invalid IPNetwork %s' % (addr,))
netaddr.core.AddrFormatError: invalid IPNetwork .
Originally created by @nniehoff on GitHub (May 13, 2021). ### NetBox version v2.11.3 ### Python version 3.8 ### Steps to Reproduce 1. Run `python netbox/manage.py nbshell` 2. Run the following: ```python from ipam.models import Prefix Prefix(prefix="10.0.0.0/8").get_available_prefixes() ``` If you get the prefix object from the db and call the function everything works as expected: ```python from ipam.models import Prefix Prefix(prefix="10.0.0.0/8").save() Prefix.objects.get(prefix="10.0.0.0/8").get_available_prefixes() IPSet(['10.0.0.0/8']) ``` ### Expected Behavior ```python IPSet(['10.0.0.0/8']) ``` ### Observed Behavior ```python Traceback (most recent call last): File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 125, in str_to_int return _struct.unpack('>I', _inet_pton(AF_INET, addr))[0] OSError: illegal IP address string passed to inet_pton During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 311, in __init__ self._value = self._module.str_to_int(addr, flags) File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 129, in str_to_int raise AddrFormatError('%r is not a valid IPv4 address string!' % (addr,)) netaddr.core.AddrFormatError: '.' is not a valid IPv4 address string! During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 799, in parse_ip_network ip = IPAddress(val1, module.version, flags=INET_PTON) File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 313, in __init__ raise AddrFormatError('base address %r is not IPv%d' netaddr.core.AddrFormatError: base address '.' is not IPv4 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 263, in expand_partial_address tokens = ['%d' % int(o) for o in addr.split('.')] File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 263, in <listcomp> tokens = ['%d' % int(o) for o in addr.split('.')] ValueError: invalid literal for int() with base 10: '' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 942, in __init__ value, prefixlen = parse_ip_network(module, addr, File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 803, in parse_ip_network expanded_addr = _ipv4.expand_partial_address(val1) File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 267, in expand_partial_address raise error netaddr.core.AddrFormatError: invalid partial IPv4 address: '.'! During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<console>", line 1, in <module> File "/opt/netbox-2.11.3/netbox/ipam/models/ip.py", line 415, in get_available_prefixes prefix = netaddr.IPSet(self.prefix) File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/sets.py", line 121, in __init__ for cidr in cidr_merge(mergeable): File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 1600, in cidr_merge net = IPNetwork(ip) File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 953, in __init__ raise AddrFormatError('invalid IPNetwork %s' % (addr,)) netaddr.core.AddrFormatError: invalid IPNetwork . ```
adam closed this issue 2025-12-29 19:21:59 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4905