question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bind() included resources

See original GitHub issue

Included resources that are instantiated in extract_included under renders.py doesn’t bind fields field_name and parent. I don’t have a definitive use case yet, but sometimes it’s needed to understand the tree structure of serializers.

https://github.com/django-json-api/django-rest-framework-json-api/blob/0892e3a8a4dbad9630d70e2b78e18b242a8b057d/rest_framework_json_api/renderers.py#L322 https://github.com/django-json-api/django-rest-framework-json-api/blob/0892e3a8a4dbad9630d70e2b78e18b242a8b057d/rest_framework_json_api/renderers.py#L342

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sliverccommented, Apr 2, 2021

JSON API spec resp. DJA follows REST principles. One of the REST constraint is uniform interface

Any single resource should contain each and everything in its representation.

The compound document feature in JSON API spec is basically a feature to avoid too many http request but the resource as such remains the same as when fetched through its own end point.

In your example PostDetailSerializer when called per include query parameter does not serialize everything in its representation (body is missing). An API user therefore has a resource which does not contain everything but how should a user know what is missing? They can’t as the resource has a unique id and per REST guideline it is expected to always get the full resource (JS framework such as ember.js heavily rely on this convention for caching of resources for instance).

A pitfall to be avoided. If it is a real concern that the body is too large what I would do in your example is to create another resource postBody and move the content of the body to that resource. This can then additionally be included as post.body and the api user can decide whether they need it or not.

I hope this makes a bit clearer why those parameters are not binded.

I am closing this issue therefore. If there are any other comments or example on how to use those parameters please feel free to comment. We can always reopen the issue again.

0reactions
sliverccommented, Apr 7, 2021

I do not know your complete use case but I am not sure it is a good idea to have posts on Category as this might end up to be a really large request (with or without includes). Another solution is to have a filter category on the post end point which can be called when you want to show all posts of a certain category.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Binding as a Resource - wpf - Stack Overflow
Direct answer to your question is "yes, you can define a binding as a resource". The problem here is how do you then...
Read more >
Binding Resource | Twilio
Full API reference for the Binding resource in the Twilio Notify API. Learn how to create, fetch (get), read (list), and delete Binding...
Read more >
4. BIND 9 Configuration Reference
Types of Resource Records and When to Use Them ... The include statement facilitates the administration of configuration files by permitting the reading...
Read more >
Resource binding overview - Win32 apps | Microsoft Learn
Create one or more root signature objects – one for every different binding configuration an application needs. Create shaders and pipeline ...
Read more >
Function.prototype.bind() - JavaScript - MDN Web Docs - Mozilla
The bind() method creates a new function that, when called, ... The bound function will store the parameters passed — which include the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found