Skip to content

Fix resource name inconsistency between included and relationships #229

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions example/tests/integration/test_model_resource_name.py
Original file line number Diff line number Diff line change
@@ -103,6 +103,11 @@ def test_type_match_on_included_and_inline_with_serializer_resource_name(self, c

_check_relationship_and_included_comment_type_are_the_same(client, reverse("entry-list"))

def test_type_match_on_included_and_inline_without_serializer_resource_name(self, client):
serializers.CommentSerializer.Meta.resource_name = None

_check_relationship_and_included_comment_type_are_the_same(client, reverse("entry-list"))

def test_type_match_on_included_and_inline_with_serializer_resource_name_and_JSONAPIMeta(self, client):
models.Comment.__bases__ += (_PatchedModel,)
serializers.CommentSerializer.Meta.resource_name = "resource_name_from_serializer"
6 changes: 5 additions & 1 deletion rest_framework_json_api/renderers.py
Original file line number Diff line number Diff line change
@@ -292,9 +292,13 @@ def extract_included(fields, resource, resource_instance, included_resources):
for position in range(len(serializer_data)):
serializer_resource = serializer_data[position]
nested_resource_instance = relation_queryset[position]
resource_type = (
relation_type or
utils.get_resource_type_from_instance(nested_resource_instance)
)
included_data.append(
JSONRenderer.build_json_resource_obj(
serializer_fields, serializer_resource, nested_resource_instance, relation_type
serializer_fields, serializer_resource, nested_resource_instance, resource_type
)
)
included_data.extend(