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

Do not raise if error_code is missing. Avoid dropping response body o… #1192

Merged

Conversation

eddiestudies
Copy link
Contributor

@eddiestudies eddiestudies commented May 3, 2019

If error_code is missing in the exception response, an KeyError: 'error_code' is raised. This drops the error message completely.

What changes are proposed in this pull request?

Use get instead of accessing the key directly for error_code in response json. This avoids a KeyError for a missing "error_code" key in new server implementations. It may be worth introducing a specific default, for now the PR proposes InternalError as the default error_code which is the current default.

How is this patch tested?

A test, using the new class omitting the "error_code" top level property was added.

(Details)

Release Notes

Is this a user-facing change?

  • [X ] No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

(Details in 1-2 sentences. You can just refer to another PR with a description if this PR is part of a larger change.)

What component(s) does this PR affect?

  • UI
  • CLI
  • API
  • REST-API
  • Examples
  • Docs
  • [X ] Tracking
  • Projects
  • Artifacts
  • Models
  • Scoring
  • Serving
  • R
  • Java
  • Python

How should the PR be classified in the release notes? Choose one:

  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • [X ] rn/none - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

@@ -37,7 +37,7 @@ def serialize_as_json(self):
class RestException(MlflowException):
"""Exception thrown on non 200-level responses from the REST API"""
def __init__(self, json):
error_code = json['error_code']
error_code = json.get('error_code')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean for this to be json.get('error_code', INTERNAL_ERROR) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently I left the default value to MlflowException's default value( None -> INTERNAL_ERROR). I can make it explicit or, if there is a better error_code, we can set it here as you described.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both options are fine.
One difference is, if there is no message nor error_code in the json then the exception will have no message.

@akshaya-a
Copy link
Contributor

@aarondav for thoughts

Copy link
Contributor

@tomasatdatabricks tomasatdatabricks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@@ -37,7 +37,7 @@ def serialize_as_json(self):
class RestException(MlflowException):
"""Exception thrown on non 200-level responses from the REST API"""
def __init__(self, json):
error_code = json['error_code']
error_code = json.get('error_code')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both options are fine.
One difference is, if there is no message nor error_code in the json then the exception will have no message.

@aarondav
Copy link
Contributor

aarondav commented May 8, 2019

LGTM - will merge after Travis passes!

@aarondav aarondav self-assigned this May 8, 2019
@aarondav aarondav merged commit cbc9c9e into mlflow:master May 8, 2019
@sueann sueann added the rn/none List under Small Changes in Changelogs. label May 10, 2019
avflor pushed a commit to avflor/mlflow that referenced this pull request Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn/none List under Small Changes in Changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants