Json-api renderer breaking when paired with JWT packages (simple-jwt & drf-jwt)
See original GitHub issueRan into this issue today while setting up a backend -
line 479, in build_json_resource_obj ('id', encoding.force_text(resource_instance.pk) if resource_instance else None), AttributeError: 'dict' object has no attribute 'pk'
Found out that is occurring from this line of code located inside of renderers.py
('id', encoding.force_text(resource_instance.pk) if resource_instance else None),
in particular its the “resource_instance.pk” thats blowing up. This occurs whenever I’m using JWT packages simple-jwt or drf-jwt
If I change the line to
('id', encoding.force_text(resource_instance['user'].pk) if resource_instance else None),
Everything works. Ideally I’d like to avoid having to go down the route of forking, does anyone know how I could get past this? It seems the renderer is making an assumption about how the resource_instance should be returned from the JWT serializer.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
rest_framework_simplejwt package — Simple JWT 5.2.2.post4 ...
An authentication plugin that authenticates requests through a JSON web token provided in a request header without performing a database lookup to obtain...
Read more >Profile for Django LLC - Linknovate
Break the API into 2 parts — Instead of sending item details in first API just ... 3.1 .1 drf-jwt == 1.13 .3...
Read more >Setting up JWT Authentication - Thinkster.io
Rendering User objects Create conduit/apps/authentication/renderers.py. There's nothing new or interesting happening here, so just read through the comments in ...
Read more >Simple Index
abstract-rendering · abstractfactory ... ad-testing-packaging-cs207 · ad-udacitydistributions ... ak-djangorestframework-jsonapi · ak-gchartwrapper
Read more >Customizing JWT response from django-rest-framework ...
For example: to customize simpleJWT response by adding username and groups,. enter image description here. Override the validate method in ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This serializer looks a bit odd because it returns user as data but doesn’t define field. If it wouldn’t need to be serialized it would need to be defined as
RelatedField
marked as read_only.Also I just quickly tested it and cannot reproduce an error:
Test code:
This reproduces following output:
Maybe overwriting serializer and marking user as related field might help you already.
Otherwise could you provide a PR potentially which reproduces this error within the json api example?
@ewelinabuturla This issue is old and even though your issue might look similar it might not be. And when I read through it seems that I was actually never able to reproduce this issue.
I am locking this conversation. But if your issue still exists best open a pull request with a reproducing test for your issue (can also be an example application or similar if this is easier).