-
Notifications
You must be signed in to change notification settings - Fork 192
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: REST API "download=False" error #5576
Conversation
There was a problem hiding this 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 @eimrek !
Would you mind adding a test that failed before your fix and now passes?
This reverts commit 0a9dac3.
for more information, see https://pre-commit.ci
Ok, I figured out the source of this problem: The aiida-core/aiida/restapi/common/utils.py Line 15 in cb82327
in flask 1.x was based on As a result, in Aiida 2.0 REST (where flask 1 was updated to flask 2), bytes objects are not supported any more. I implemented a conversion of a bytes array into Similar issue is probably also the source of #5575 but this PR doesn't fix that. i will investigate that in a separate PR. I'll try to add a test as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This is related to #5573 aiida-core/aiida/restapi/resources.py Line 459 in cb82327
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to combine #5573 to this PR.
Thanks @unkcpz. I disagree, as the source issues are different. #5573 fixes a bug that has been there forever, and affects how boolean query parameters are parsed. The issue of this PR is in the encoding of the binary string to JSON, that was introduced by the aiida 2.0 upgrade. Although the issue comes out in case of I think it makes sense to isolate the code changes that fix specific issues, instead of merging everything together. the current PR fixes the linked issue (and the PR of #5573 does not affect this). PR #5573 fixes a separate issue, namely, that lowercase "false" in the query parameters is interpreted as True, but could be bypassed by specifying an uppercase "False" instead. I suspect this is the reason is it was not fixed for over 3 years. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eimrek sorry for the back and forth. One more minor request, others are all good. Could you then rebase and make a detailed commit message? Thanks.
try: | ||
return o.decode('utf-8') | ||
except (UnicodeDecodeError, AttributeError): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think an elif
for bytes type makes more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This discussion here seems to prefer the duck-typing version: https://stackoverflow.com/questions/34869889/what-is-the-proper-way-to-determine-if-an-object-is-a-bytes-like-object-in-pytho
My proposal for #5574
for context, see the discussion in the issue.