Skip to content

Commit 969543f

Browse files
committed
The values of the id and type members MUST be strings
1 parent 0ddd140 commit 969543f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

rest_framework_json_api/utils.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def format_value(value, format_type=None):
131131
def build_json_resource_obj(fields, resource, resource_instance, resource_name):
132132
resource_data = [
133133
('type', resource_name),
134-
('id', resource_instance.pk),
134+
('id', encoding.force_text(resource_instance.pk)),
135135
('attributes', extract_attributes(fields, resource)),
136136
]
137137
relationships = extract_relationships(fields, resource, resource_instance)
@@ -212,7 +212,7 @@ def extract_relationships(fields, resource, resource_instance):
212212
relation_type = get_related_resource_type(field)
213213
related = getattr(resource_instance, field_name).all()
214214
for relation in related:
215-
relation_data.append(OrderedDict([('type', relation_type), ('id', relation.pk)]))
215+
relation_data.append(OrderedDict([('type', relation_type), ('id', encoding.force_text(relation.pk))]))
216216

217217
data.update({field_name: {
218218
'links': {
@@ -239,7 +239,7 @@ def extract_relationships(fields, resource, resource_instance):
239239
{
240240
field_name: {
241241
'data': (OrderedDict([
242-
('type', relation_type), ('id', relation_id)
242+
('type', relation_type), ('id', encoding.force_text(relation_id))
243243
]) if relation_id is not None else None)
244244
}
245245
}
@@ -281,7 +281,7 @@ def extract_relationships(fields, resource, resource_instance):
281281
nested_resource_instance = resource_instance_manager[position]
282282
relation_data.append(
283283
OrderedDict([
284-
('type', relation_type), ('id', nested_resource_instance.pk)
284+
('type', relation_type), ('id', encoding.force_text(nested_resource_instance.pk))
285285
]))
286286

287287
data.update({field_name: {'data': relation_data}})
@@ -296,7 +296,7 @@ def extract_relationships(fields, resource, resource_instance):
296296
'data': (
297297
OrderedDict([
298298
('type', relation_type),
299-
('id', getattr(resource_instance, field_name).pk)
299+
('id', encoding.force_text(getattr(resource_instance, field_name).pk))
300300
]) if resource.get(field_name) else None)
301301
}
302302
})

0 commit comments

Comments
 (0)