In a Django (v3.1.2) ReST Framework (DRF v3.12.1) Application, I am using the Django ReST Framework JSON API (DJA) extension (v3.2.0) to consume and produce resources in JSON:API format (Content-Type application/vnd.api+json). This DJA extension provides its own JSON parser and renderer.
In addition, I chose dj-rest-auth (v1.1.2) for authentication resources. However, it seems to be incompatible with DJA: When I issue a login request in JSON:API format, like
{
"data": {
"type": "LoginView",
"attributes": {
"username": "user",
"password": "pwd"
}
}
}
the server fails to render the response with the exception 'dict' object has no attribute 'pk'
at ... python3.8/site-packages/rest_framework_json_api/renderers.py, line 502, in build_json_resource_obj
. Debugging into the request, I find that DJA expects the serializer output serializer.instance
to have a private key (pk
) field, from which the DJA renderer derives metadata like the ID that must be present in a application/vnd.api+json resource.
I have two questions:
For the record and to close this question: I did not find out what the problem was. However, the exact use case described above is now working flawlessly with the following combination of libraries: