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

set content-type to json for beamline get routes #1392

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mxcubeweb/routes/beamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_func(name):
**{"return": getattr(app.mxcubecore.get_adapter(name), attr)(**args)}
)

return make_response(result.json(), 200)
return make_response(result.dict(), 200)
Copy link
Collaborator

@axelboc axelboc Sep 10, 2024

Choose a reason for hiding this comment

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

How this change leads to the Content-Type header being set to application/json is just hilarious 😹

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, one would have expected .json() to also set Content-Type to application/json

Copy link
Member

Choose a reason for hiding this comment

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

Well, actually, on second thought it somehow makes sense. I guess json() returns a string so the content is interpreted as text, while a dictionary always can be interpreted as json when returned as a response

Copy link
Contributor Author

@elmjag elmjag Sep 10, 2024

Choose a reason for hiding this comment

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

This is Flask logic. By default, if you give it a string, it creates a text response. If you give it a dictionary, it makes it a application/json response.

And yes, result is a pydantic model (I think), so it's json() method returns a string.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, sure it does make sense.


route_url = f"{atype}/<string:name>/{attr}"
endpoint = f"{atype}_{attr}"
Expand Down
Loading