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

2.5.0 API Docs broken: Field name interface_b is not valid for model Interface. #2662

Closed
ghost opened this issue Dec 10, 2018 · 3 comments
Closed
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@ghost
Copy link

ghost commented Dec 10, 2018

Environment

  • Python version: 3.6.6
  • NetBox version: 2.5.0

API Docs broken by 2.5.0 cable/interface_connection changes.
When viewing api/docs the following error message appears:
"Failed to load API definitions
Errors
Fetch error
Internal Server Error http:///api/docs/?format=openapi"

==> /srv/netbox/shared/application.log <==
Internal Server Error: /api/docs/
Traceback (most recent call last):
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/rest_framework/views.py", line 495, in dispatch
response = self.handle_exception(exc)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/rest_framework/views.py", line 455, in handle_exception
self.raise_uncaught_exception(exc)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/rest_framework/views.py", line 492, in dispatch
response = handler(request, *args, **kwargs)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/views.py", line 95, in get
schema = generator.get_schema(request, self.public)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/generators.py", line 215, in get_schema
paths, prefix = self.get_paths(endpoints, components, request, public)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/generators.py", line 358, in get_paths
operation = self.get_operation(view, path, prefix, method, components, request)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/generators.py", line 400, in get_operation
operation = view_inspector.get_operation(operation_keys)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/inspectors/view.py", line 29, in get_operation
body = self.get_request_body_parameters(consumes)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/inspectors/view.py", line 83, in get_request_body_parameters
schema = self.get_request_body_schema(serializer)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/inspectors/view.py", line 148, in get_request_body_schema
return self.serializer_to_schema(serializer)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/inspectors/base.py", line 374, in serializer_to_schema
self.field_inspectors, 'get_schema', serializer, {'field_inspectors': self.field_inspectors}
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/inspectors/base.py", line 71, in probe_inspectors
result = method(obj, **kwargs)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/inspectors/field.py", line 39, in get_schema
return self.probe_field_inspectors(serializer, openapi.Schema, self.use_definitions)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/inspectors/base.py", line 175, in probe_field_inspectors
swagger_object_type=swagger_object_type, use_references=use_references, **kwargs
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/inspectors/base.py", line 71, in probe_inspectors
result = method(obj, **kwargs)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/inspectors/field.py", line 124, in field_to_swagger_object
actual_schema = definitions.setdefault(ref_name, make_schema_definition)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/openapi.py", line 653, in setdefault
ret = maker()
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/drf_yasg/inspectors/field.py", line 92, in make_schema_definition
for property_name, child in serializer.fields.items():
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/rest_framework/serializers.py", line 363, in fields
for key, value in self.get_fields().items():
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/rest_framework/serializers.py", line 1047, in get_fields
source, info, model, depth
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/rest_framework/serializers.py", line 1192, in build_field
return self.build_unknown_field(field_name, model_class)
File "/srv/netbox/current/venv-py3/lib/python3.6/site-packages/rest_framework/serializers.py", line 1304, in build_unknown_field
(field_name, model_class.name)
django.core.exceptions.ImproperlyConfigured: Field name interface_b is not valid for model Interface.

@jeremystretch jeremystretch added type: bug A confirmed report of unexpected behavior in the application status: accepted This issue has been accepted for implementation labels Dec 11, 2018
@jeremystretch
Copy link
Member

It looks like drf_yasg is throwing an error when trying to process InterfaceConnectionSerializer:

class InterfaceConnectionSerializer(ValidatedModelSerializer):
    interface_a = serializers.SerializerMethodField()
    interface_b = NestedInterfaceSerializer(source='connected_endpoint')
    connection_status = ChoiceField(choices=CONNECTION_STATUS_CHOICES, required=False)

    class Meta:
        model = Interface
        fields = ['interface_a', 'interface_b', 'connection_status']

    def get_interface_a(self, obj):
        context = {'request': self.context['request']}
        return NestedInterfaceSerializer(instance=obj, context=context).data

It's worth noting that the serializer itself functions normally.

@lampwins lampwins added the status: blocked Another issue or external requirement is preventing implementation label Dec 11, 2018
@lampwins
Copy link
Contributor

This will be covered in #2665

@jeremystretch jeremystretch removed the status: blocked Another issue or external requirement is preventing implementation label Dec 12, 2018
@jeremystretch
Copy link
Member

This ended up being fixed by #2680. The API view was corrected to be read-only.

@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