Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing captchetat responses #392

Merged
merged 3 commits into from Apr 12, 2024

Conversation

maudetes
Copy link
Contributor

@maudetes maudetes commented Apr 11, 2024

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 to ujson.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.

If no Content-Type is set on response, it expects it to be application/json
Copy link
Contributor

@Jorek57 Jorek57 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix and the clear explanation about what was happening 🙏

@maudetes maudetes merged commit 05ef1e1 into datagouv:master Apr 12, 2024
7 checks passed
@maudetes maudetes deleted the fix/captchetat-content-type branch April 12, 2024 08:03
@maudetes
Copy link
Contributor Author

cc @ThibaudDauce for information regarding ujson, if we wanna reintroduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants