-
Notifications
You must be signed in to change notification settings - Fork 11
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
Rest API does not take into account some arguments when submitting #31
Comments
GuilloteauQ
changed the title
Rest API do not take into account some arguments when submitting
Rest API does not take into account some arguments when submitting
Apr 14, 2023
The following diff --git a/oar/rest_api/utils.py b/oar/rest_api/utils.py
index 0fc292f..feac236 100644
--- a/oar/rest_api/utils.py
+++ b/oar/rest_api/utils.py
@@ -7,7 +7,6 @@ from flask import abort, current_app, request
from oar.lib import config
from oar.lib.utils import integer_types, reraise, to_unicode
-
class WSGIProxyFix(object):
def __init__(self, app):
self.app = app
@@ -69,7 +68,7 @@ class Arg(object):
self.required = required
self.dest = dest
self.error = error
- self.locations = locations or self.DEFAULT_LOCATIONS
+ self.locations = locations if locations else self.DEFAULT_LOCATIONS
def raw_value(self, value):
if value is not None:
@@ -111,7 +110,7 @@ class ArgParser(object):
self.argmap = argmap
def get_value(self, data, name, argobj):
- if isinstance(argobj.type, ListArg) and not argobj.type.sep:
+ if isinstance(argobj.type, ListArg) and not argobj.type.sep and not isinstance(data, dict):
return data.getlist(name)
else:
return data.get(name, self.MISSING)
@@ -119,6 +118,7 @@ class ArgParser(object):
def parse_arg(self, argname, argobj):
"""Pull a form value from the request."""
for location in argobj.locations:
+
value = self.MISSING
if location == "querystring" and request.args:
value = self.get_value(request.args, argname, argobj)
@@ -136,7 +136,7 @@ class ArgParser(object):
def convert_bool(self, value):
"""Try to convert ``value`` to a Boolean."""
- if value.lower() in ("True", "yes", "1"):
+ if value.lower() in ("true", "yes", "1"):
return True
if value.lower() in ("false", "no", "0"):
return False
diff --git a/oar/rest_api/views/job.py b/oar/rest_api/views/job.py
index bb536f3..4a15eda 100644
--- a/oar/rest_api/views/job.py
+++ b/oar/rest_api/views/job.py
@@ -79,7 +79,7 @@ def index(
"reservation": Arg(str),
"checkpoint": Arg(int, default=0),
"signal": Arg(int),
- "type": Arg([str], dest="types"),
+ "type": Arg([str], dest="types", locations=("json",)),
"directory": Arg(str),
"project": Arg(str),
"name": Arg(str),
--- The issue seems to be linked to the Line 41 in 402aaeb
The form location returns the empty list ([] ), while it is actually not empty.Forcing the location to be json fixed the issue.
|
Can you create a pull request ? Or push it to oar if the tests pass ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using the Rest API i noticed that some arguments in my json were not taking into account for the submission.
here is an example of request i used:
In this case, OAR will submit a job that will sleep for 1 minute, but the resources used will be the default values (one
resource_id
and 1 hour walltime for my config).The problem seems to come from the management of the types in flask.
Fields that uses the defaults values event when passed arguments in the requests are the ones having the following argument:
with
Arg
coming fromoar3/oar/rest_api/utils.py
Line 38 in 402aaeb
Here are some examples:
oar3/oar/rest_api/views/job.py
Line 69 in 402aaeb
oar3/oar/rest_api/views/job.py
Line 82 in 402aaeb
I am not sure what is going on in this
Arg
class, so i cannot really propose a solution.The text was updated successfully, but these errors were encountered: