unsupported operand type(s) for %: 'AddrFormatError' and 'tuple' when setting invalid interface mac address using api #2499

Closed
opened 2025-12-29 18:19:24 +01:00 by adam · 1 comment
Owner

Originally created by @a31amit on GitHub (Apr 5, 2019).

Environment

  • Python version: 3.7
  • NetBox version: 2.5.3

It seems like it should have been fixed under old Bug - https://github.com/digitalocean/netbox/issues/2444

But somehow this is still

Steps to Reproduce

Attempt to set an invalid MAC address on an interface using the following API request:

curl -X PATCH \
-H "Authorization: Token " \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://localhost:8000/api/dcim/interfaces// \
--data '{"mac_address": "01234567890123456789"}'

Expected Behavior

Should be a validation error

Observed Behavior

Netbox Instance crash with errors as below

Traceback:

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/netaddr/eui/__init__.py" in _set_value
  442.                     self._value = self._module.str_to_int(value)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/netaddr/strategy/eui48.py" in str_to_int
  176.             raise AddrFormatError('%r is not a supported MAC format!' % addr)

During handling of the above exception ('01234567890123456789' is not a supported MAC format!), another exception occurred:

File "/opt/netbox/netbox/dcim/fields.py" in to_python
  32.             return EUI(value, version=48, dialect=mac_unix_expanded_uppercase)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/netaddr/eui/__init__.py" in __init__
  387.         self.value = addr

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/netaddr/eui/__init__.py" in _set_value
  445.                         % (value, self._module.version))

During handling of the above exception (address '01234567890123456789' is not an EUIv48), another exception occurred:

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/serializers.py" in to_internal_value
  488.                 validated_value = field.run_validation(primitive_value)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/fields.py" in run_validation
  536.         value = self.to_internal_value(data)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/fields.py" in to_internal_value
  1924.         return self.model_field.to_python(data)

File "/opt/netbox/netbox/dcim/fields.py" in to_python
  34.             raise ValidationError(e)

During handling of the above exception (["address '01234567890123456789' is not an EUIv48"]), another exception occurred:

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/fields.py" in get_error_detail
  240.         error_dict = exc_info.error_dict

During handling of the above exception ('ValidationError' object has no attribute 'error_dict'), another exception occurred:

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = self.process_exception_by_middleware(e, request)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  124.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
  54.         return view_func(*args, **kwargs)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/viewsets.py" in view
  116.             return self.dispatch(request, *args, **kwargs)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/views.py" in dispatch
  495.             response = self.handle_exception(exc)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/views.py" in handle_exception
  455.             self.raise_uncaught_exception(exc)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/views.py" in dispatch
  492.             response = handler(request, *args, **kwargs)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/mixins.py" in partial_update
  84.         return self.update(request, *args, **kwargs)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/mixins.py" in update
  69.         serializer.is_valid(raise_exception=True)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/serializers.py" in is_valid
  236.                 self._validated_data = self.run_validation(self.initial_data)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/serializers.py" in run_validation
  434.         value = self.to_internal_value(data)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/serializers.py" in to_internal_value
  494.                 errors[field.field_name] = get_error_detail(exc)

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/fields.py" in get_error_detail
  245.             for error in exc_info.error_list]

File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/fields.py" in 
  245.             for error in exc_info.error_list]

Exception Type: TypeError at /api/dcim/interfaces/15332/ Exception Value: unsupported operand type(s) for %: 'AddrFormatError' and 'tuple'
Request information:

Originally created by @a31amit on GitHub (Apr 5, 2019). <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.7 * NetBox version: 2.5.3 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a wrapper like pynetbox. --> It seems like it should have been fixed under old Bug - https://github.com/digitalocean/netbox/issues/2444 But somehow this is still ### Steps to Reproduce Attempt to set an invalid MAC address on an interface using the following API request: <pre> curl -X PATCH \ -H "Authorization: Token <TOKEN>" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ http://localhost:8000/api/dcim/interfaces/<PK>/ \ --data '{"mac_address": "01234567890123456789"}' </pre> <!-- What did you expect to happen? --> ### Expected Behavior Should be a validation error <!-- What happened instead? --> ### Observed Behavior Netbox Instance crash with errors as below <pre> Traceback: File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/netaddr/eui/__init__.py" in _set_value 442. self._value = self._module.str_to_int(value) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/netaddr/strategy/eui48.py" in str_to_int 176. raise AddrFormatError('%r is not a supported MAC format!' % addr) During handling of the above exception ('01234567890123456789' is not a supported MAC format!), another exception occurred: File "/opt/netbox/netbox/dcim/fields.py" in to_python 32. return EUI(value, version=48, dialect=mac_unix_expanded_uppercase) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/netaddr/eui/__init__.py" in __init__ 387. self.value = addr File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/netaddr/eui/__init__.py" in _set_value 445. % (value, self._module.version)) During handling of the above exception (address '01234567890123456789' is not an EUIv48), another exception occurred: File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/serializers.py" in to_internal_value 488. validated_value = field.run_validation(primitive_value) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/fields.py" in run_validation 536. value = self.to_internal_value(data) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/fields.py" in to_internal_value 1924. return self.model_field.to_python(data) File "/opt/netbox/netbox/dcim/fields.py" in to_python 34. raise ValidationError(e) During handling of the above exception (["address '01234567890123456789' is not an EUIv48"]), another exception occurred: File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/fields.py" in get_error_detail 240. error_dict = exc_info.error_dict During handling of the above exception ('ValidationError' object has no attribute 'error_dict'), another exception occurred: File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner 34. response = get_response(request) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response 126. response = self.process_exception_by_middleware(e, request) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response 124. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/django/views/decorators/csrf.py" in wrapped_view 54. return view_func(*args, **kwargs) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/viewsets.py" in view 116. return self.dispatch(request, *args, **kwargs) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/views.py" in dispatch 495. response = self.handle_exception(exc) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/views.py" in handle_exception 455. self.raise_uncaught_exception(exc) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/views.py" in dispatch 492. response = handler(request, *args, **kwargs) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/mixins.py" in partial_update 84. return self.update(request, *args, **kwargs) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/mixins.py" in update 69. serializer.is_valid(raise_exception=True) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/serializers.py" in is_valid 236. self._validated_data = self.run_validation(self.initial_data) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/serializers.py" in run_validation 434. value = self.to_internal_value(data) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/serializers.py" in to_internal_value 494. errors[field.field_name] = get_error_detail(exc) File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/fields.py" in get_error_detail 245. for error in exc_info.error_list] File "/opt/netbox/netbox25_env/lib/python3.7/site-packages/rest_framework/fields.py" in <listcomp> 245. for error in exc_info.error_list] Exception Type: TypeError at /api/dcim/interfaces/15332/ Exception Value: unsupported operand type(s) for %: 'AddrFormatError' and 'tuple' Request information: </pre>
adam added the type: bugstatus: accepted labels 2025-12-29 18:19:24 +01:00
adam closed this issue 2025-12-29 18:19:24 +01:00
Author
Owner

@DanSheps commented on GitHub (Apr 5, 2019):

The bug is in the raised exception, however your are not sending a supported mac (so it still would have raised an exception).

@DanSheps commented on GitHub (Apr 5, 2019): The bug is in the raised exception, however your are not sending a supported mac (so it still would have raised an exception).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2499