You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
checks only for 'detail' inside the data and this creates a problem when a custom exception handling exists or even if some response actually has the key "detail" inside.
Proposal: Validate via the response status code. If it is in the range of HTTP 2xx it's True.
The text was updated successfully, but these errors were encountered:
I ran into this issue. My solution is to patch the renderer as:
classXLSXRendererPatch(XLSXRenderer):
""" Modification on base XLSX renderer to prevent it from serializing exceptions as xlsx; see https://github.com/django-commons/drf-excel/issues/26 """defrender(self, data, accepted_media_type=None, renderer_context=None):
if (
(renderer_contextand (ctx:=renderer_context.get('response')) andctx.status_code!=200) or
(isinstance(data, dict) and ('error'indataor'error_code'indata))
):
self.media_type='application/json'returnjson.dumps(data)
returnsuper().render(data, accepted_media_type, renderer_context)
This checks HTTP 200 response, and also for non-presence of error/error_code. Additionally, I needed to change the media_type or it would send the default xlsx content type back for the JSONified error.
You may also need to get rid of XLSXFileMixin, or patch that as well, since it seems to try and fetch a filename for the content disposition header.
There is a problem occuring with the validation checker. The current one:
checks only for 'detail' inside the data and this creates a problem when a custom exception handling exists or even if some response actually has the key "detail" inside.
Proposal: Validate via the response status code. If it is in the range of HTTP 2xx it's True.
The text was updated successfully, but these errors were encountered: