Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bfb3c2c

Browse files
committedOct 3, 2021
Add relationships support for pointers in errors
Signed-off-by: Mehdy Khoshnoody <[email protected]>
1 parent 29971b4 commit bfb3c2c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed
 

‎rest_framework_json_api/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,14 @@ def format_drf_errors(response, context, exc):
394394
errors.extend(format_error_object(message, "/data", response))
395395
# handle all errors thrown from serializers
396396
else:
397+
relationship_fields = getattr(
398+
context["view"].serializer_class, "included_serializers", dict()
399+
).keys()
400+
397401
for field, error in response.data.items():
398402
field = format_field_name(field)
399-
pointer = "/data/attributes/{}".format(field)
403+
rel = "relationships" if field in relationship_fields else "attributes"
404+
pointer = "/data/{}/{}".format(rel, field)
400405
if isinstance(exc, Http404) and isinstance(error, str):
401406
# 404 errors don't have a pointer
402407
errors.extend(format_error_object(error, None, response))

0 commit comments

Comments
 (0)
Please sign in to comment.