-
Notifications
You must be signed in to change notification settings - Fork 63
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
[refactor] Replace conditional ladder in requests utils #237
base: master
Are you sure you want to change the base?
Conversation
evalai/utils/requests.py
Outdated
# TODO: Add support for PUT request | ||
# TODO: Add support for PATCH request | ||
# TODO: Add support for DELETE request |
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.
Please remove these TODOs as the requests.request
will implement this 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.
Okay. That's done! :D 👍
@vkartik97 @RishabhJain2018 Shall I explicitly remove support for PUT, PATCH, DELETE requests? |
Can you please provide detailed information regarding this? |
evalai/utils/requests.py
Outdated
echo( | ||
style( | ||
"\nCould not establish a connection to EvalAI." | ||
" Please check the Host URL.\n", | ||
"Use `evalai challenges` to fetch the active challenges." |
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.
@vkartik97 As in, it wasn't there in the code previously. It is not fully supported. Like, it might not make sense to show this message in that case (for example for DELETE method). Also, I'm not sure if we have the support for this in the backend (please correct me if I missed something).
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.
@vkartik97 It would be better to have some error messages or blocking requests for security reasons (example using DELETE method). It can still be possible with a custom script, but a warning block here can make everything clearer. For reference: https://www.owasp.org/index.php/Test_HTTP_Methods_(OTG-CONFIG-006)
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 am thinking of having something like:
if method in [PUT,PATCH, DELETE] then:
return or/and throw error
else:
.
.
.
What are your opinions on this?
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.
Great, looks good to me.
I checked the exceptions list provided by requests package but it doesn't include an InvalidMethodError
. So I was thinking we could echo
a message saying the method is unsupported and then perform a sys.exit
.
That is:
if method in ["PUT", "PATCH", "DELETE"]:
echo("Method not supported ...")
sys.exit(1)
else:
.
.
.
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.
Instead of echo
and exit
, what are opinions on using raise Exception('{METHOD} not supported by make_request')
? The reason for using exceptions is that the method make_request
should have a behavior to inform the user/programmer that a exceptional behavior has occurred, here it is "PUT", "PATCH", "DELETE" is not supported
.
Please let me know if this doesn't seem correct way.
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.
@vkartik97 I think that is a valid point. I agree raising an Exception will be better 👍
I will update the PR with the same.
This comment has been minimized.
This comment has been minimized.
@Ram81 @vkartik97 I have changed the handling mechanism a bit, but the behavior of the function is the same, and with the suggested additions.
The efficiency and readability of the code has increased. |
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.
@nikochiko nice work LGTM 👍
@Ram81 Can I get an approval on the GCI page? |
As a Google Code-In task.
Changes proposed:
Replace conditional ladder in requests utils, with a single
requests.request
call.