Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f15e9a4

Browse files
martinmaillardkhornberg
authored andcommitted
Fix included resource type inconsistency (django-json-api#229)
When setting `resource_name = None`, the related instance's resource name is used in `relationships`, but `None` is used in `included`. This is related to django-json-api#94 and django-json-api#124
1 parent b439112 commit f15e9a4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

‎example/tests/integration/test_model_resource_name.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ def test_type_match_on_included_and_inline_with_serializer_resource_name(self, c
103103

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

106+
def test_type_match_on_included_and_inline_without_serializer_resource_name(self, client):
107+
serializers.CommentSerializer.Meta.resource_name = None
108+
109+
_check_relationship_and_included_comment_type_are_the_same(client, reverse("entry-list"))
110+
106111
def test_type_match_on_included_and_inline_with_serializer_resource_name_and_JSONAPIMeta(self, client):
107112
models.Comment.__bases__ += (_PatchedModel,)
108113
serializers.CommentSerializer.Meta.resource_name = "resource_name_from_serializer"

‎rest_framework_json_api/renderers.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,13 @@ def extract_included(fields, resource, resource_instance, included_resources):
292292
for position in range(len(serializer_data)):
293293
serializer_resource = serializer_data[position]
294294
nested_resource_instance = relation_queryset[position]
295+
resource_type = (
296+
relation_type or
297+
utils.get_resource_type_from_instance(nested_resource_instance)
298+
)
295299
included_data.append(
296300
JSONRenderer.build_json_resource_obj(
297-
serializer_fields, serializer_resource, nested_resource_instance, relation_type
301+
serializer_fields, serializer_resource, nested_resource_instance, resource_type
298302
)
299303
)
300304
included_data.extend(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /