django-json-api / django-rest-framework-json-api

JSON:API support for Django REST framework
https://django-rest-framework-json-api.readthedocs.org/
BSD 2-Clause "Simplified" License
1.19k stars 295 forks source link

Fix the format_errors bug when response data is None #1229

Open ericinfins opened 5 months ago

ericinfins commented 5 months ago

Fixes #

Related to the PR: https://github.com/django-json-api/django-rest-framework-json-api/pull/1121 Add the test case to support it

Description of the Change

Fix: TypeError: object of type 'NoneType' has no len()

Checklist

sliverc commented 4 months ago

Thanks for following up on this. I will take a look at it at some point and will give you feedback. Just writing to let you know that I saw it.

sliverc commented 2 months ago

I have finally got around to take a look at this. Great to see how this can be reproduced by using vanilla DRF classes.

It is though as I expected that this fix does avoid the exception, however the output of the fix is not JSON:API compliant. It simply returns

{
  "errors": None
}

but the value of errors needs to be a list and each error object must at least have one member. I think the easiest is to add a single error object with the status code as a string.