Skip to content

Commit

Permalink
chore(pylint): Reenable raise-missing-from check (#16266)
Browse files Browse the repository at this point in the history
Co-authored-by: John Bodley <john.bodley@airbnb.com>
  • Loading branch information
john-bodley and John Bodley authored Aug 16, 2021
1 parent 36bc7b0 commit be7065f
Show file tree
Hide file tree
Showing 80 changed files with 216 additions and 211 deletions.
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ confidence=
disable=
missing-docstring,
too-many-lines,
raise-missing-from,
duplicate-code,

[REPORTS]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def run(self) -> None:
return None
except DAODeleteFailedError as ex:
logger.exception(ex.exception)
raise AnnotationBulkDeleteFailedError()
raise AnnotationBulkDeleteFailedError() from ex

def validate(self) -> None:
# Validate/populate model exists
Expand Down
2 changes: 1 addition & 1 deletion superset/annotation_layers/annotations/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def run(self) -> Model:
annotation = AnnotationDAO.create(self._properties)
except DAOCreateFailedError as ex:
logger.exception(ex.exception)
raise AnnotationCreateFailedError()
raise AnnotationCreateFailedError() from ex
return annotation

def validate(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion superset/annotation_layers/annotations/commands/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def run(self) -> Model:
annotation = AnnotationDAO.delete(self._model)
except DAODeleteFailedError as ex:
logger.exception(ex.exception)
raise AnnotationDeleteFailedError()
raise AnnotationDeleteFailedError() from ex
return annotation

def validate(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion superset/annotation_layers/annotations/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def run(self) -> Model:
annotation = AnnotationDAO.update(self._model, self._properties)
except DAOUpdateFailedError as ex:
logger.exception(ex.exception)
raise AnnotationUpdateFailedError()
raise AnnotationUpdateFailedError() from ex
return annotation

def validate(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions superset/annotation_layers/annotations/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def bulk_delete(models: Optional[List[Annotation]], commit: bool = True) -> None
)
if commit:
db.session.commit()
except SQLAlchemyError:
except SQLAlchemyError as ex:
if commit:
db.session.rollback()
raise DAODeleteFailedError()
raise DAODeleteFailedError() from ex

@staticmethod
def validate_update_uniqueness(
Expand Down
4 changes: 2 additions & 2 deletions superset/annotation_layers/annotations/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
def validate_json(value: Union[bytes, bytearray, str]) -> None:
try:
utils.validate_json(value)
except SupersetException:
raise ValidationError("JSON not valid")
except SupersetException as ex:
raise ValidationError("JSON not valid") from ex


class AnnotationPostSchema(Schema):
Expand Down
2 changes: 1 addition & 1 deletion superset/annotation_layers/commands/bulk_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run(self) -> None:
return None
except DAODeleteFailedError as ex:
logger.exception(ex.exception)
raise AnnotationLayerBulkDeleteFailedError()
raise AnnotationLayerBulkDeleteFailedError() from ex

def validate(self) -> None:
# Validate/populate model exists
Expand Down
2 changes: 1 addition & 1 deletion superset/annotation_layers/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def run(self) -> Model:
annotation_layer = AnnotationLayerDAO.create(self._properties)
except DAOCreateFailedError as ex:
logger.exception(ex.exception)
raise AnnotationLayerCreateFailedError()
raise AnnotationLayerCreateFailedError() from ex
return annotation_layer

def validate(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion superset/annotation_layers/commands/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run(self) -> Model:
annotation_layer = AnnotationLayerDAO.delete(self._model)
except DAODeleteFailedError as ex:
logger.exception(ex.exception)
raise AnnotationLayerDeleteFailedError()
raise AnnotationLayerDeleteFailedError() from ex
return annotation_layer

def validate(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion superset/annotation_layers/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def run(self) -> Model:
annotation_layer = AnnotationLayerDAO.update(self._model, self._properties)
except DAOUpdateFailedError as ex:
logger.exception(ex.exception)
raise AnnotationLayerUpdateFailedError()
raise AnnotationLayerUpdateFailedError() from ex
return annotation_layer

def validate(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions superset/annotation_layers/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def bulk_delete(
).delete(synchronize_session="fetch")
if commit:
db.session.commit()
except SQLAlchemyError:
except SQLAlchemyError as ex:
if commit:
db.session.rollback()
raise DAODeleteFailedError()
raise DAODeleteFailedError() from ex

@staticmethod
def has_annotations(model_id: Union[int, List[int]]) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions superset/charts/commands/bulk_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def run(self) -> None:
ChartDAO.bulk_delete(self._models)
except DeleteFailedError as ex:
logger.exception(ex.exception)
raise ChartBulkDeleteFailedError()
raise ChartBulkDeleteFailedError() from ex

def validate(self) -> None:
# Validate/populate model exists
Expand All @@ -67,5 +67,5 @@ def validate(self) -> None:
for model in self._models:
try:
check_ownership(model)
except SupersetSecurityException:
raise ChartForbiddenError()
except SupersetSecurityException as ex:
raise ChartForbiddenError() from ex
2 changes: 1 addition & 1 deletion superset/charts/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def run(self) -> Model:
chart = ChartDAO.create(self._properties)
except DAOCreateFailedError as ex:
logger.exception(ex.exception)
raise ChartCreateFailedError()
raise ChartCreateFailedError() from ex
return chart

def validate(self) -> None:
Expand Down
8 changes: 4 additions & 4 deletions superset/charts/commands/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def run(self, **kwargs: Any) -> Dict[str, Any]:
payload = self._query_context.get_payload(
cache_query_context=cache_query_context, force_cached=force_cached
)
except CacheLoadError as exc:
raise ChartDataCacheLoadError(exc.message)
except CacheLoadError as ex:
raise ChartDataCacheLoadError(ex.message) from ex

# TODO: QueryContext should support SIP-40 style errors
for query in payload["queries"]:
Expand All @@ -77,8 +77,8 @@ def set_query_context(self, form_data: Dict[str, Any]) -> QueryContext:
self._form_data = form_data
try:
self._query_context = ChartDataQueryContextSchema().load(self._form_data)
except KeyError:
raise ValidationError("Request is incorrect")
except KeyError as ex:
raise ValidationError("Request is incorrect") from ex
except ValidationError as error:
raise error

Expand Down
6 changes: 3 additions & 3 deletions superset/charts/commands/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def run(self) -> Model:
chart = ChartDAO.delete(self._model)
except DAODeleteFailedError as ex:
logger.exception(ex.exception)
raise ChartDeleteFailedError()
raise ChartDeleteFailedError() from ex
return chart

def validate(self) -> None:
Expand All @@ -70,5 +70,5 @@ def validate(self) -> None:
# Check ownership
try:
check_ownership(self._model)
except SupersetSecurityException:
raise ChartForbiddenError()
except SupersetSecurityException as ex:
raise ChartForbiddenError() from ex
6 changes: 3 additions & 3 deletions superset/charts/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def run(self) -> Model:
chart = ChartDAO.update(self._model, self._properties)
except DAOUpdateFailedError as ex:
logger.exception(ex.exception)
raise ChartUpdateFailedError()
raise ChartUpdateFailedError() from ex
return chart

def validate(self) -> None:
Expand All @@ -89,8 +89,8 @@ def validate(self) -> None:
if not is_query_context_update(self._properties):
try:
check_ownership(self._model)
except SupersetSecurityException:
raise ChartForbiddenError()
except SupersetSecurityException as ex:
raise ChartForbiddenError() from ex

# Validate/Populate datasource
if datasource_id is not None:
Expand Down
4 changes: 2 additions & 2 deletions superset/commands/importers/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def run(self) -> None:
try:
self._import(db.session, self._configs, self.overwrite)
db.session.commit()
except Exception:
except Exception as ex:
db.session.rollback()
raise self.import_error()
raise self.import_error() from ex

# pylint: disable=too-many-branches
def validate(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions superset/commands/importers/v1/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def run(self) -> None:
try:
self._import(db.session, self._configs, self.overwrite, self.force_data)
db.session.commit()
except Exception:
except Exception as ex:
db.session.rollback()
raise self.import_error()
raise self.import_error() from ex

@classmethod
def _get_uuids(cls) -> Set[str]:
Expand Down
14 changes: 7 additions & 7 deletions superset/commands/importers/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def load_yaml(file_name: str, content: str) -> Dict[str, Any]:
"""Try to load a YAML file"""
try:
return yaml.safe_load(content)
except yaml.parser.ParserError:
except yaml.parser.ParserError as ex:
logger.exception("Invalid YAML in %s", file_name)
raise ValidationError({file_name: "Not a valid YAML file"})
raise ValidationError({file_name: "Not a valid YAML file"}) from ex


def load_metadata(contents: Dict[str, str]) -> Dict[str, str]:
Expand All @@ -63,15 +63,15 @@ def load_metadata(contents: Dict[str, str]) -> Dict[str, str]:
metadata = load_yaml(METADATA_FILE_NAME, contents[METADATA_FILE_NAME])
try:
MetadataSchema().load(metadata)
except ValidationError as exc:
except ValidationError as ex:
# if the version doesn't match raise an exception so that the
# dispatcher can try a different command version
if "version" in exc.messages:
raise IncorrectVersionError(exc.messages["version"][0])
if "version" in ex.messages:
raise IncorrectVersionError(ex.messages["version"][0]) from ex

# otherwise we raise the validation error
exc.messages = {METADATA_FILE_NAME: exc.messages}
raise exc
ex.messages = {METADATA_FILE_NAME: ex.messages}
raise ex

return metadata

Expand Down
4 changes: 2 additions & 2 deletions superset/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ def get_datasource_by_id(datasource_id: int, datasource_type: str) -> BaseDataso
return ConnectorRegistry.get_datasource(
datasource_type, datasource_id, db.session
)
except DatasetNotFoundError:
raise DatasourceNotFoundValidationError()
except DatasetNotFoundError as ex:
raise DatasourceNotFoundValidationError() from ex
4 changes: 2 additions & 2 deletions superset/common/query_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def processing_time_offsets( # pylint: disable=too-many-locals
)
query_object_clone.to_dttm = get_past_or_future(offset, outer_to_dttm)
except ValueError as ex:
raise QueryObjectValidationError(str(ex))
raise QueryObjectValidationError(str(ex)) from ex
# make sure subquery use main query where clause
query_object_clone.inner_from_dttm = outer_from_dttm
query_object_clone.inner_to_dttm = outer_to_dttm
Expand Down Expand Up @@ -417,7 +417,7 @@ def get_viz_annotation_data(
payload = viz_obj.get_payload()
return payload["data"]
except SupersetException as ex:
raise QueryObjectValidationError(error_msg_from_exception(ex))
raise QueryObjectValidationError(error_msg_from_exception(ex)) from ex

def get_annotation_data(self, query_obj: QueryObject) -> Dict[str, Any]:
"""
Expand Down
2 changes: 1 addition & 1 deletion superset/connectors/druid/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def pre_update(self, item: "DruidColumnInlineView") -> None:
try:
dimension_spec = json.loads(item.dimension_spec_json)
except ValueError as ex:
raise ValueError("Invalid Dimension Spec JSON: " + str(ex))
raise ValueError("Invalid Dimension Spec JSON: " + str(ex)) from ex
if not isinstance(dimension_spec, dict):
raise ValueError("Dimension Spec must be a JSON object")
if "outputName" not in dimension_spec:
Expand Down
10 changes: 5 additions & 5 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def get_fetch_values_predicate(self) -> TextClause:
"Error in jinja expression in fetch values predicate: %(msg)s",
msg=ex.message,
)
)
) from ex

def values_for_column(self, column_name: str, limit: int = 10000) -> List[Any]:
"""Runs query against sqla to retrieve some
Expand Down Expand Up @@ -818,7 +818,7 @@ def get_rendered_sql(
"Error while rendering virtual dataset query: %(msg)s",
msg=ex.message,
)
)
) from ex
sql = sqlparse.format(sql.strip("\t\r\n; "), strip_comments=True)
if not sql:
raise QueryObjectValidationError(_("Virtual dataset query cannot be empty"))
Expand Down Expand Up @@ -929,7 +929,7 @@ def _get_sqla_row_level_filters(
except TemplateError as ex:
raise QueryObjectValidationError(
_("Error in jinja expression in RLS filters: %(msg)s", msg=ex.message,)
)
) from ex

def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
self,
Expand Down Expand Up @@ -1252,7 +1252,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
"Error in jinja expression in WHERE clause: %(msg)s",
msg=ex.message,
)
)
) from ex
where_clause_and += [sa.text("({})".format(where))]
having = extras.get("having")
if having:
Expand All @@ -1264,7 +1264,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
"Error in jinja expression in HAVING clause: %(msg)s",
msg=ex.message,
)
)
) from ex
having_clause_and += [sa.text("({})".format(having))]
if apply_fetch_values_predicate and self.fetch_values_predicate:
qry = qry.where(self.get_fetch_values_predicate())
Expand Down
4 changes: 2 additions & 2 deletions superset/connectors/sqla/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ def get_virtual_table_metadata(dataset: "SqlaTable") -> List[Dict[str, str]]:
result = db_engine_spec.fetch_data(cursor, limit=1)
result_set = SupersetResultSet(result, cursor.description, db_engine_spec)
cols = result_set.columns
except Exception as exc:
raise SupersetGenericDBErrorException(message=str(exc))
except Exception as ex:
raise SupersetGenericDBErrorException(message=str(ex)) from ex
return cols
2 changes: 1 addition & 1 deletion superset/css_templates/commands/bulk_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def run(self) -> None:
return None
except DAODeleteFailedError as ex:
logger.exception(ex.exception)
raise CssTemplateBulkDeleteFailedError()
raise CssTemplateBulkDeleteFailedError() from ex

def validate(self) -> None:
# Validate/populate model exists
Expand Down
4 changes: 2 additions & 2 deletions superset/css_templates/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def bulk_delete(models: Optional[List[CssTemplate]], commit: bool = True) -> Non
)
if commit:
db.session.commit()
except SQLAlchemyError:
except SQLAlchemyError as ex:
if commit:
db.session.rollback()
raise DAODeleteFailedError()
raise DAODeleteFailedError() from ex
6 changes: 3 additions & 3 deletions superset/dao/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def create(cls, properties: Dict[str, Any], commit: bool = True) -> Model:
db.session.commit()
except SQLAlchemyError as ex: # pragma: no cover
db.session.rollback()
raise DAOCreateFailedError(exception=ex)
raise DAOCreateFailedError(exception=ex) from ex
return model

@classmethod
Expand All @@ -125,7 +125,7 @@ def update(
db.session.commit()
except SQLAlchemyError as ex: # pragma: no cover
db.session.rollback()
raise DAOUpdateFailedError(exception=ex)
raise DAOUpdateFailedError(exception=ex) from ex
return model

@classmethod
Expand All @@ -140,5 +140,5 @@ def delete(cls, model: Model, commit: bool = True) -> Model:
db.session.commit()
except SQLAlchemyError as ex: # pragma: no cover
db.session.rollback()
raise DAODeleteFailedError(exception=ex)
raise DAODeleteFailedError(exception=ex) from ex
return model
Loading

0 comments on commit be7065f

Please sign in to comment.