Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
a31amit opened this issue Apr 4, 2019 · 1 comment
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@a31amit
Copy link

a31amit commented Apr 4, 2019

Environment

  • Python version: 3.7
  • NetBox version: 2.5.3

It seems like it should have been fixed under old Bug - #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:

@DanSheps
Copy link
Member

DanSheps commented 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 DanSheps added status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application and removed status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application labels Apr 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

2 participants