Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See failing tests in https://app.circleci.com/pipelines/github/etalab/udata-front/3411/workflows/789166fd-c91e-4c3b-82f1-32b508f3882e/jobs/17989.
Indeed, if no Content-Type is set on response, flask_restx expects it to be application/json.
It ends up wrongfully calling json
dumps()
on req.content, which will be bytes.Even if unexpected, it wasn't failing until then thanks to
ujson
.ujson
having been removed since opendatateam/udata#3006, it now fallbacks on json in flask_restx make response.json.dumps(b'some bytes')
now fails, on contrary toujson.dumps(b'some bytes')
.We may want to reintroduce ujson for performance reasons, but should probably not apply a json dump on bytes output in any case: ultrajson/ultrajson#264.
To prevent dumping the content, we make sure to build the response explicitly and associate it with upstream captchetat Content-Type.