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

feat: convert backend chart errors to the new error type #9753

Merged
merged 1 commit into from May 13, 2020

Conversation

etr2460
Copy link
Member

@etr2460 etr2460 commented May 6, 2020

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

Continuing to implement SIP-40, this time adding some of the backend logic. My plan is as follows:

  • Start replacing the error field in api responses with the errors list of SupersetError Objects
  • Support backwards compatibility on the frontend by pulling the message out of the errors list into the error field again
  • Provide the necessary info to the front end to render better error messages once designs are ready

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

No ui changes

TEST PLAN

Test dashboards loading with and without errors in charts, see errors still render properly
Test SQL Lab with and without query errors

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

to: @john-bodley @villebro @dpgaspar

@etr2460 etr2460 force-pushed the erik-ritter--error-messages-2 branch from 8c32f79 to 6232b47 Compare May 6, 2020 16:54
@@ -39,7 +39,7 @@ class Datasource(BaseSupersetView):
def save(self) -> Response:
data = request.form.get("data")
if not isinstance(data, str):
return json_error_response("Request missing data field.", status="500")
return json_error_response("Request missing data field.", status=500)
Copy link
Member Author

Choose a reason for hiding this comment

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

cleaning up some typing

from typing import Any, Dict


class SupersetErrorType(str, Enum):
Copy link
Member Author

Choose a reason for hiding this comment

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

inheriting from str provides automatic json serialization

@etr2460 etr2460 force-pushed the erik-ritter--error-messages-2 branch from 6232b47 to ed1e2fe Compare May 6, 2020 17:06
FRONTEND_CSRF_ERROR: 'FRONTEND_CSRF_ERROR',
FRONTEND_NETWORK_ERROR: 'FRONTEND_NETWORK_ERROR',
FRONTEND_TIMEOUT_ERROR: 'FRONTEND_TIMEOUT_ERROR',

Copy link
Member

Choose a reason for hiding this comment

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

Nit. Nix empty lines?

Copy link
Member Author

Choose a reason for hiding this comment

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

I put the empty lines here to try and organize these errors into categories, since i expect there to be many of them going forward

setup.cfg Outdated
@@ -45,7 +45,7 @@ combine_as_imports = true
include_trailing_comma = true
line_length = 88
known_first_party = superset
known_third_party =alembic,apispec,backoff,bleach,celery,click,colorama,contextlib2,croniter,cryptography,dataclasses,dateutil,flask,flask_appbuilder,flask_babel,flask_caching,flask_compress,flask_login,flask_migrate,flask_sqlalchemy,flask_talisman,flask_testing,flask_wtf,geohash,geopy,humanize,isodate,jinja2,markdown,markupsafe,marshmallow,msgpack,numpy,pandas,parsedatetime,pathlib2,polyline,prison,pyarrow,pyhive,pytz,retry,selenium,setuptools,simplejson,sphinx_rtd_theme,sqlalchemy,sqlalchemy_utils,sqlparse,werkzeug,wtforms,wtforms_json,yaml
known_third_party =alembic,apispec,backoff,bleach,celery,click,colorama,contextlib2,croniter,cryptography,dateutil,flask,flask_appbuilder,flask_babel,flask_caching,flask_compress,flask_login,flask_migrate,flask_sqlalchemy,flask_talisman,flask_testing,flask_wtf,geohash,geopy,humanize,isodate,jinja2,markdown,markupsafe,marshmallow,msgpack,numpy,pandas,parsedatetime,pathlib2,polyline,prison,pyarrow,pyhive,pytz,retry,selenium,setuptools,simplejson,sphinx_rtd_theme,sqlalchemy,sqlalchemy_utils,sqlparse,werkzeug,wtforms,wtforms_json,yaml
Copy link
Member

Choose a reason for hiding this comment

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

dataclasses should be included here as it's not part of the stdlib in Python 3.6.

FRONTEND_CSRF_ERROR = "FRONTEND_CSRF_ERROR"
FRONTEND_NETWORK_ERROR = "FRONTEND_NETWORK_ERROR"
FRONTEND_TIMEOUT_ERROR = "FRONTEND_TIMEOUT_ERROR"

Copy link
Member

Choose a reason for hiding this comment

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

Nit. Nix empty lines?

message: str
error_type: SupersetErrorType
level: ErrorLevel
extra: Dict[str, Any]
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to make this optional?

Copy link
Member Author

Choose a reason for hiding this comment

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

I went back and forth on that... I guess optional is probably safer in the long run, and means people don't need to remember to initialize with an empty dict, although it pushes a bit of work to the front end to check that the object exists

superset/viz.py Outdated

error = dataclasses.asdict(
SupersetError(
message="{}".format(ex),
Copy link
Member

Choose a reason for hiding this comment

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

Why not message=str(ex)?

Copy link
Member Author

Choose a reason for hiding this comment

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

this was copy pasted from before, i assume str(ex) works the same way, so i'll change it

superset/viz.py Outdated
message="{}".format(ex),
level=ErrorLevel.ERROR,
type=SupersetErrorType.VIZ_GET_DF_ERROR,
extra={},
Copy link
Member

Choose a reason for hiding this comment

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

See note regarding making this optional.

superset/viz.py Outdated
extra={},
)
)
if not self.errors:
Copy link
Member

Choose a reason for hiding this comment

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

See previous comment which would simplify this to self.errors.append(error).

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure how your previous comment would affect this

Copy link
Member

Choose a reason for hiding this comment

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

@etr2460 apologies if I'm misreading the logic but isn't self.errors going to be a list by default and thus rather than:

if not self.errors:
    self.errors = [error]
else:
    self.errors.append(error)

this could be:

self.errors.append(error)

@etr2460 etr2460 force-pushed the erik-ritter--error-messages-2 branch 3 times, most recently from 213096b to 81a1153 Compare May 6, 2020 17:39
Copy link
Member Author

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

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

@john-bodley replied to/addressed your comments

FRONTEND_CSRF_ERROR: 'FRONTEND_CSRF_ERROR',
FRONTEND_NETWORK_ERROR: 'FRONTEND_NETWORK_ERROR',
FRONTEND_TIMEOUT_ERROR: 'FRONTEND_TIMEOUT_ERROR',

Copy link
Member Author

Choose a reason for hiding this comment

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

I put the empty lines here to try and organize these errors into categories, since i expect there to be many of them going forward

message: str
error_type: SupersetErrorType
level: ErrorLevel
extra: Dict[str, Any]
Copy link
Member Author

Choose a reason for hiding this comment

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

I went back and forth on that... I guess optional is probably safer in the long run, and means people don't need to remember to initialize with an empty dict, although it pushes a bit of work to the front end to check that the object exists

superset/viz.py Outdated

error = dataclasses.asdict(
SupersetError(
message="{}".format(ex),
Copy link
Member Author

Choose a reason for hiding this comment

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

this was copy pasted from before, i assume str(ex) works the same way, so i'll change it

superset/viz.py Outdated
extra={},
)
)
if not self.errors:
Copy link
Member Author

Choose a reason for hiding this comment

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

not sure how your previous comment would affect this

@etr2460 etr2460 force-pushed the erik-ritter--error-messages-2 branch from 81a1153 to d00f6dd Compare May 6, 2020 17:43
@codecov-io
Copy link

codecov-io commented May 6, 2020

Codecov Report

Merging #9753 into master will increase coverage by 0.19%.
The diff coverage is 80.43%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9753      +/-   ##
==========================================
+ Coverage   70.79%   70.98%   +0.19%     
==========================================
  Files         587      184     -403     
  Lines       30435    17854   -12581     
  Branches     3152        0    -3152     
==========================================
- Hits        21545    12673    -8872     
+ Misses       8776     5181    -3595     
+ Partials      114        0     -114     
Flag Coverage Δ
#cypress ?
#javascript ?
#python 70.98% <80.43%> (+0.02%) ⬆️
Impacted Files Coverage Δ
superset/viz_sip38.py 0.00% <0.00%> (ø)
superset/views/datasource.py 93.33% <50.00%> (ø)
superset/viz.py 72.00% <66.66%> (+0.03%) ⬆️
superset/connectors/sqla/models.py 87.80% <100.00%> (-0.77%) ⬇️
superset/db_engine_specs/base.py 87.67% <100.00%> (-0.12%) ⬇️
superset/errors.py 100.00% <100.00%> (ø)
superset/models/helpers.py 87.95% <100.00%> (+0.06%) ⬆️
superset/views/base.py 72.35% <100.00%> (ø)
superset/views/core.py 75.11% <100.00%> (+0.22%) ⬆️
superset/db_engine_specs/sqlite.py 63.33% <0.00%> (-10.01%) ⬇️
... and 409 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65d185f...7b87ad2. Read the comment docs.

@mistercrunch mistercrunch added the airbnb Airbnb related label May 6, 2020
):
self.df: pd.DataFrame = df
self.query: str = query
self.duration: int = duration
self.status: str = status
self.error_message: Optional[str] = error_message
self.errors: Optional[List[Dict[str, Any]]] = errors
Copy link
Member

Choose a reason for hiding this comment

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

@etr2460 sorry this could be:

self.errors: List[Dict[str, Any]] = errors or []

which simplifies the related content in viz.py.

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually think it's better to keep this optional? Because at the end of the day we send errors down to the client, and i think it being null is better than []

Copy link
Member

Choose a reason for hiding this comment

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

@dpgaspar @villebro any thoughts on consistency here, i.e., should we use an empty list or None to represent no errors?

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved to empty list to make the backend logic a bit neater

Copy link
Member

@john-bodley john-bodley left a comment

Choose a reason for hiding this comment

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

@etr2460 I think you'll also have to update viz_sip38.py. cc @villebro.

@etr2460 etr2460 force-pushed the erik-ritter--error-messages-2 branch 5 times, most recently from 389f774 to dc776e9 Compare May 12, 2020 22:13
@etr2460 etr2460 force-pushed the erik-ritter--error-messages-2 branch 3 times, most recently from bd9517b to 7b87ad2 Compare May 13, 2020 00:32
@etr2460 etr2460 force-pushed the erik-ritter--error-messages-2 branch from 7b87ad2 to fa15615 Compare May 13, 2020 00:57
@etr2460 etr2460 merged commit 83ec736 into apache:master May 13, 2020
@etr2460 etr2460 added the SIP-40 label Jun 2, 2020
@@ -48,6 +50,12 @@ export default function getClientErrorObject(
.json()
.then(errorJson => {
let error = { ...responseObject, ...errorJson };

// Backwards compatibility for old error renderers with the new error object
if (error.errors && error.errors.length > 0) {
Copy link

Choose a reason for hiding this comment

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

I suspect this new line cause some error_details logged as empty.
this is how front-end use error field:
https://github.com/apache/incubator-superset/blob/38a6bd79da2be8c13a89a5f67f77faeb55c4e08b/superset-frontend/src/chart/chartAction.js#L403

Can you check what is in err.errors[0].message?

@mistercrunch mistercrunch added the 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels label Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
airbnb Airbnb related 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 0.37.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants