Object-level validation errors given an incorrect source.pointer
arttuperala opened this issue · 0 comments
arttuperala commented
Description of the Bug Report
When raising a non-field ValidationError in a serializer in accordance with the DRF documentation, the error is attributed to a non-existing /data/attributes/non_field_errors path instead of /data.
from rest_framework_json_api import serializers
class ProductSerializer(serializers.ModelSerializer):
def validate(self, data):
if data.get("best_before_date") and data.get("expiry_date"):
raise serializers.ValidationError(
"Specify either a best before date or an expiry date."
)
return data{
"errors": [
{
"detail": "Specify either a best before date or an expiry date.",
"status": "400",
"source": {
"pointer": "/data/attributes/non_field_errors"
},
"code": "invalid"
}
]
}Complete minimal example available here.
Discussed in #1135
Checklist
- Certain that this is a bug (if unsure or you have a question use discussions instead)
- Code snippet or unit test added to reproduce bug