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

BUG: fixed model serve fail with HTTP 400 on Bad Request. #5003

Merged
merged 12 commits into from Dec 3, 2021
2 changes: 1 addition & 1 deletion mlflow/pyfunc/scoring_server/__init__.py
Expand Up @@ -85,7 +85,7 @@ def infer_and_parse_json_input(json_input, schema: Schema = None):
"Failed to parse input from JSON. Ensure that input is a valid JSON"
" formatted string."
),
error_code=MALFORMED_REQUEST,
error_code=BAD_REQUEST,
)

if isinstance(decoded_input, list):
Expand Down
8 changes: 4 additions & 4 deletions tests/models/test_cli.py
Expand Up @@ -31,7 +31,7 @@
get_safe_port,
pyfunc_serve_and_score_model,
)
from mlflow.protos.databricks_pb2 import ErrorCode, MALFORMED_REQUEST
from mlflow.protos.databricks_pb2 import ErrorCode, BAD_REQUEST
from mlflow.pyfunc.scoring_server import (
CONTENT_TYPE_JSON_SPLIT_ORIENTED,
CONTENT_TYPE_JSON,
Expand Down Expand Up @@ -452,12 +452,12 @@ def _validate_with_rest_endpoint(scoring_proc, host_port, df, x, sk_model):
# Try examples of bad input, verify we get a non-200 status code
for content_type in [CONTENT_TYPE_JSON_SPLIT_ORIENTED, CONTENT_TYPE_CSV, CONTENT_TYPE_JSON]:
scoring_response = endpoint.invoke(data="", content_type=content_type)
assert scoring_response.status_code == 500, (
"Expected server failure with error code 500, got response with status code %s "
assert scoring_response.status_code == 400, (
"Expected server failure with error code 400, got response with status code %s "
"and body %s" % (scoring_response.status_code, scoring_response.text)
)
scoring_response_dict = json.loads(scoring_response.content)
assert "error_code" in scoring_response_dict
assert scoring_response_dict["error_code"] == ErrorCode.Name(MALFORMED_REQUEST)
assert scoring_response_dict["error_code"] == ErrorCode.Name(BAD_REQUEST)
assert "message" in scoring_response_dict
assert "stack_trace" in scoring_response_dict