KeyError when adding FHRP group type "other" and IP address at same time #5873

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

Originally created by @candlerb on GitHub (Jan 4, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.1.4

Python version

3.8

Steps to Reproduce

  1. Go to IPAM > FHRP Group > +
  2. Protocol: Other
  3. Group ID: 1
  4. Address: 1.2.3.4/24
  5. Status: Active
  6. Create

Expected Behavior

A new FHRP group to be created, together with a new IP address assigned to it.

Observed Behavior

Server Error

There was a problem with your request. Please contact an administrator.


The complete exception is provided below:

<class 'KeyError'>
'other'

Python version: 3.8.10
NetBox version: 3.1.4
If further assistance is required, please post to the NetBox discussion forum on GitHub.


Backtrace:

Traceback (most recent call last):
  File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/netbox/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/netbox/views/generic.py", line 321, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/views.py", line 93, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/netbox/netbox/netbox/views/generic.py", line 353, in post
    obj = form.save()
  File "/opt/netbox/netbox/ipam/forms/models.py", line 583, in save
    role=FHRP_PROTOCOL_ROLE_MAPPINGS[self.cleaned_data['protocol']],

Exception Type: KeyError at /ipam/fhrp-groups/add/
Exception Value: 'other'

It appears that it's trying to map the FHRP type to an IP Address role in FHRP_PROTOCOL_ROLE_MAPPINGS, but is missing a choice for "other". I think ROLE_VIP is the most appropriate choice, although None would be OK.

This could be done either by adding a new entry to FHRP_PROTOCOL_ROLE_MAPPINGS:

--- a/netbox/ipam/constants.py
+++ b/netbox/ipam/constants.py
@@ -65,6 +65,7 @@ FHRP_PROTOCOL_ROLE_MAPPINGS = {
     FHRPGroupProtocolChoices.PROTOCOL_HSRP: IPAddressRoleChoices.ROLE_HSRP,
     FHRPGroupProtocolChoices.PROTOCOL_GLBP: IPAddressRoleChoices.ROLE_GLBP,
     FHRPGroupProtocolChoices.PROTOCOL_CARP: IPAddressRoleChoices.ROLE_CARP,
+    FHRPGroupProtocolChoices.PROTOCOL_OTHER: IPAddressRoleChoices.ROLE_VIP,
 }


or by having a default:

role=FHRP_PROTOCOL_ROLE_MAPPINGS.get(self.cleaned_data['protocol'], IPAddressRoleChoices.ROLE_VIP),
Originally created by @candlerb on GitHub (Jan 4, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.1.4 ### Python version 3.8 ### Steps to Reproduce 1. Go to IPAM > FHRP Group > + 2. Protocol: Other 3. Group ID: 1 4. Address: 1.2.3.4/24 5. Status: Active 6. Create ### Expected Behavior A new FHRP group to be created, together with a new IP address assigned to it. ### Observed Behavior ## Server Error There was a problem with your request. Please contact an administrator. ------- The complete exception is provided below: ``` <class 'KeyError'> 'other' ``` Python version: 3.8.10 NetBox version: 3.1.4 If further assistance is required, please post to the NetBox discussion forum on GitHub. ------- Backtrace: ``` Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/opt/netbox/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view return self.dispatch(request, *args, **kwargs) File "/opt/netbox/netbox/netbox/views/generic.py", line 321, in dispatch return super().dispatch(request, *args, **kwargs) File "/opt/netbox/netbox/utilities/views.py", line 93, in dispatch return super().dispatch(request, *args, **kwargs) File "/opt/netbox/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch return handler(request, *args, **kwargs) File "/opt/netbox/netbox/netbox/views/generic.py", line 353, in post obj = form.save() File "/opt/netbox/netbox/ipam/forms/models.py", line 583, in save role=FHRP_PROTOCOL_ROLE_MAPPINGS[self.cleaned_data['protocol']], Exception Type: KeyError at /ipam/fhrp-groups/add/ Exception Value: 'other' ``` It appears that it's trying to map the FHRP type to an IP Address role in `FHRP_PROTOCOL_ROLE_MAPPINGS`, but is missing a choice for "other". I think `ROLE_VIP` is the most appropriate choice, although `None` would be OK. This could be done either by adding a new entry to `FHRP_PROTOCOL_ROLE_MAPPINGS`: ``` --- a/netbox/ipam/constants.py +++ b/netbox/ipam/constants.py @@ -65,6 +65,7 @@ FHRP_PROTOCOL_ROLE_MAPPINGS = { FHRPGroupProtocolChoices.PROTOCOL_HSRP: IPAddressRoleChoices.ROLE_HSRP, FHRPGroupProtocolChoices.PROTOCOL_GLBP: IPAddressRoleChoices.ROLE_GLBP, FHRPGroupProtocolChoices.PROTOCOL_CARP: IPAddressRoleChoices.ROLE_CARP, + FHRPGroupProtocolChoices.PROTOCOL_OTHER: IPAddressRoleChoices.ROLE_VIP, } ``` or by having a default: ``` role=FHRP_PROTOCOL_ROLE_MAPPINGS.get(self.cleaned_data['protocol'], IPAddressRoleChoices.ROLE_VIP), ```
adam added the type: bugstatus: accepted labels 2025-12-29 19:33:43 +01:00
adam closed this issue 2025-12-29 19:33:43 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5873