Skip to content

Error raised when sending OPTIONS request to relationship view #315

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

Closed
valerymelou opened this issue Jan 10, 2017 · 3 comments · Fixed by #633
Closed

Error raised when sending OPTIONS request to relationship view #315

valerymelou opened this issue Jan 10, 2017 · 3 comments · Fixed by #633

Comments

@valerymelou
Copy link

Hi.
I'm trying to send an OPTIONS request to a relationship view and the server raises a RuntimeError saying ResourceIdentifierObjectsSerializer must be initialized with a model class. I took a look in the code and I don't see how RelationshipView may specify the model class explicitly or implicitly. I don't have too much experience with the package itself so could someone please take a look at this?

@n2ygk
Copy link
Contributor

n2ygk commented Feb 8, 2018

See the declaration of ResourceIdentifierObjectSerializer where it looks like the model_class and instance have to be provided as an optional argument. In the debugger, neither is set. I'm not quite sure where that is supposed to happen. Will try to find it.

The is based on iterating through a RelationShipView's fields which was happening because I was
trying to use coreapi rest_framework.schemas.get_schema_view.

The relevant call tree is:

rest_framework.GenericAPIView.get_serializer
rest_framework.AutoSchema.get_serializer_fields

@n2ygk
Copy link
Contributor

n2ygk commented Feb 8, 2018

I added a serializer_class and this appears to have fixed it:

class WidgetRelationshipView(RelationshipView):
    queryset = Widget.objects
    serializer_class = WidgetSerializer # <<<--- add this
    self_link_view_name = 'widget-relationships'

@n2ygk
Copy link
Contributor

n2ygk commented Feb 8, 2018

But the response for coreapi and swagger are both based on application/json and not application/vnd.api+json so it's the coreapi schema, not jsonapi's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants