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 parser on get methods #155

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions mllaunchpad/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def _create_request_parser(resource_obj):
action="append" if is_array else "store",
choices=p.enum,
help=str(p.description) + " - Error: {error_msg}",
location="args" if resource_obj.method.lower() == "get" else ("json", "values", )
)
added_arguments.add(p.name)

Expand Down Expand Up @@ -176,7 +177,7 @@ def __init__(self, model_api_obj, parser):

def get(self):
args = self.parser.parse_args(
strict=True
strict=False
) # treats query_params and form_params as interchangeable
logger.debug("Received GET request with arguments: %s", args)
return self.model_api.predict_using_model(args)
Expand All @@ -190,7 +191,7 @@ def __init__(self, model_api_obj, parser, id_name):

def get(self, some_resource_id):
args = self.parser.parse_args(
strict=True
strict=False
) # treats query_params and form_params as interchangeable
args[self.id_name] = some_resource_id
logger.debug(
Expand All @@ -210,7 +211,7 @@ def __init__(self, model_api_obj, query_parser=None, file_parser=None):

def get(self):
args = self.query_parser.parse_args(
strict=True
strict=False
) # treat query_params and form_params as interchangeable
logger.debug("Received GET request with arguments: %s", args)
return self.model_api.predict_using_model(args)
Expand Down
6 changes: 5 additions & 1 deletion mllaunchpad/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ def api(settings):
ModelApi(settings.config, app, debug=True)
# Flask apps must not be run in debug mode in production, because this allows for arbitrary code execution.
# We know that and advise the user that this is only for debugging, so this is not a security issue (marked nosec):
app.run(debug=True) # nosec
app.run(
host=settings.config["api"].get("host"),
port=settings.config["api"].get("port"),
debug=True
) # nosec


@main.command()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def test_api(ma, flask, config, runner_cfg_logcfg, caplog):
) # Non-production Flask server warning
flask.assert_called()
ma.assert_called_with(config, app, debug=True)
app.run.assert_called()
app.run.assert_called_once()
assert list(app.run.call_args[1].keys()) == ["host", "port", "debug"]


@mock.patch(
Expand Down