chore: enable ruff lint rule TRY201 and B904 to improve `raise` stack traces (#29166)
This commit is contained in:
parent
5167d20f27
commit
4bb2e2f8af
|
|
@ -435,7 +435,14 @@ target-version = "py310"
|
||||||
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
||||||
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
|
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
|
||||||
# McCabe complexity (`C901`) by default.
|
# McCabe complexity (`C901`) by default.
|
||||||
select = ["E4", "E7", "E9", "F"]
|
select = [
|
||||||
|
"B904",
|
||||||
|
"E4",
|
||||||
|
"E7",
|
||||||
|
"E9",
|
||||||
|
"F",
|
||||||
|
"TRY201",
|
||||||
|
]
|
||||||
ignore = []
|
ignore = []
|
||||||
|
|
||||||
extend-select = ["I"]
|
extend-select = ["I"]
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,9 @@ def create_app(superset_config_module: Optional[str] = None) -> Flask:
|
||||||
return app
|
return app
|
||||||
|
|
||||||
# Make sure that bootstrap errors ALWAYS get logged
|
# Make sure that bootstrap errors ALWAYS get logged
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
logger.exception("Failed to create app")
|
logger.exception("Failed to create app")
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
|
|
||||||
class SupersetApp(Flask):
|
class SupersetApp(Flask):
|
||||||
|
|
|
||||||
|
|
@ -446,5 +446,6 @@ class ChartDataRestApi(ChartRestApi):
|
||||||
return ChartDataQueryContextSchema().load(form_data)
|
return ChartDataQueryContextSchema().load(form_data)
|
||||||
except KeyError as ex:
|
except KeyError as ex:
|
||||||
raise ValidationError("Request is incorrect") from ex
|
raise ValidationError("Request is incorrect") from ex
|
||||||
except ValidationError as error:
|
except ValidationError: # pylint: disable=try-except-raise
|
||||||
raise error
|
# Make sure to bubble this up
|
||||||
|
raise
|
||||||
|
|
|
||||||
|
|
@ -55,14 +55,14 @@ class ImportChartsCommand(BaseCommand):
|
||||||
return
|
return
|
||||||
except IncorrectVersionError:
|
except IncorrectVersionError:
|
||||||
logger.debug("File not handled by command, skipping")
|
logger.debug("File not handled by command, skipping")
|
||||||
except (CommandInvalidError, ValidationError) as exc:
|
except (CommandInvalidError, ValidationError):
|
||||||
# found right version, but file is invalid
|
# found right version, but file is invalid
|
||||||
logger.info("Command failed validation")
|
logger.info("Command failed validation")
|
||||||
raise exc
|
raise
|
||||||
except Exception as exc:
|
except Exception:
|
||||||
# validation succeeded but something went wrong
|
# validation succeeded but something went wrong
|
||||||
logger.exception("Error running import command")
|
logger.exception("Error running import command")
|
||||||
raise exc
|
raise
|
||||||
|
|
||||||
raise CommandInvalidError("Could not find a valid command to import file")
|
raise CommandInvalidError("Could not find a valid command to import file")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,14 +58,14 @@ class ImportDashboardsCommand(BaseCommand):
|
||||||
return
|
return
|
||||||
except IncorrectVersionError:
|
except IncorrectVersionError:
|
||||||
logger.debug("File not handled by command, skipping")
|
logger.debug("File not handled by command, skipping")
|
||||||
except (CommandInvalidError, ValidationError) as exc:
|
except (CommandInvalidError, ValidationError):
|
||||||
# found right version, but file is invalid
|
# found right version, but file is invalid
|
||||||
logger.info("Command failed validation")
|
logger.info("Command failed validation")
|
||||||
raise exc
|
raise
|
||||||
except Exception as exc:
|
except Exception:
|
||||||
# validation succeeded but something went wrong
|
# validation succeeded but something went wrong
|
||||||
logger.exception("Error running import command")
|
logger.exception("Error running import command")
|
||||||
raise exc
|
raise
|
||||||
|
|
||||||
raise CommandInvalidError("Could not find a valid command to import file")
|
raise CommandInvalidError("Could not find a valid command to import file")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ class CreateDatabaseCommand(BaseCommand):
|
||||||
engine=self._properties.get("sqlalchemy_uri", "").split(":")[0],
|
engine=self._properties.get("sqlalchemy_uri", "").split(":")[0],
|
||||||
)
|
)
|
||||||
# So we can show the original message
|
# So we can show the original message
|
||||||
raise ex
|
raise
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
event_logger.log_with_context(
|
event_logger.log_with_context(
|
||||||
action=f"db_creation_failed.{ex.__class__.__name__}",
|
action=f"db_creation_failed.{ex.__class__.__name__}",
|
||||||
|
|
@ -141,7 +141,7 @@ class CreateDatabaseCommand(BaseCommand):
|
||||||
engine=self._properties.get("sqlalchemy_uri", "").split(":")[0],
|
engine=self._properties.get("sqlalchemy_uri", "").split(":")[0],
|
||||||
)
|
)
|
||||||
# So we can show the original message
|
# So we can show the original message
|
||||||
raise ex
|
raise
|
||||||
except (
|
except (
|
||||||
DAOCreateFailedError,
|
DAOCreateFailedError,
|
||||||
DatabaseInvalidError,
|
DatabaseInvalidError,
|
||||||
|
|
|
||||||
|
|
@ -53,14 +53,14 @@ class ImportDatabasesCommand(BaseCommand):
|
||||||
return
|
return
|
||||||
except IncorrectVersionError:
|
except IncorrectVersionError:
|
||||||
logger.debug("File not handled by command, skipping")
|
logger.debug("File not handled by command, skipping")
|
||||||
except (CommandInvalidError, ValidationError) as exc:
|
except (CommandInvalidError, ValidationError):
|
||||||
# found right version, but file is invalid
|
# found right version, but file is invalid
|
||||||
logger.info("Command failed validation")
|
logger.info("Command failed validation")
|
||||||
raise exc
|
raise
|
||||||
except Exception as exc:
|
except Exception:
|
||||||
# validation succeeded but something went wrong
|
# validation succeeded but something went wrong
|
||||||
logger.exception("Error running import command")
|
logger.exception("Error running import command")
|
||||||
raise exc
|
raise
|
||||||
|
|
||||||
raise CommandInvalidError("Could not find a valid command to import file")
|
raise CommandInvalidError("Could not find a valid command to import file")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,9 @@ class CreateSSHTunnelCommand(BaseCommand):
|
||||||
return ssh_tunnel
|
return ssh_tunnel
|
||||||
except DAOCreateFailedError as ex:
|
except DAOCreateFailedError as ex:
|
||||||
raise SSHTunnelCreateFailedError() from ex
|
raise SSHTunnelCreateFailedError() from ex
|
||||||
except SSHTunnelInvalidError as ex:
|
except SSHTunnelInvalidError: # pylint: disable=try-except-raise
|
||||||
raise ex
|
# Make sure to bubble this up
|
||||||
|
raise
|
||||||
|
|
||||||
def validate(self) -> None:
|
def validate(self) -> None:
|
||||||
# TODO(hughhh): check to make sure the server port is not localhost
|
# TODO(hughhh): check to make sure the server port is not localhost
|
||||||
|
|
|
||||||
|
|
@ -127,8 +127,8 @@ class TablesDatabaseCommand(BaseCommand):
|
||||||
|
|
||||||
payload = {"count": len(tables) + len(views), "result": options}
|
payload = {"count": len(tables) + len(views), "result": options}
|
||||||
return payload
|
return payload
|
||||||
except SupersetException as ex:
|
except SupersetException:
|
||||||
raise ex
|
raise
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise DatabaseTablesUnexpectedError(ex) from ex
|
raise DatabaseTablesUnexpectedError(ex) from ex
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ class TestConnectionDatabaseCommand(BaseCommand):
|
||||||
engine=database.db_engine_spec.__name__,
|
engine=database.db_engine_spec.__name__,
|
||||||
)
|
)
|
||||||
# bubble up the exception to return a 408
|
# bubble up the exception to return a 408
|
||||||
raise ex
|
raise
|
||||||
except SSHTunnelingNotEnabledError as ex:
|
except SSHTunnelingNotEnabledError as ex:
|
||||||
event_logger.log_with_context(
|
event_logger.log_with_context(
|
||||||
action=get_log_connection_action(
|
action=get_log_connection_action(
|
||||||
|
|
@ -221,7 +221,7 @@ class TestConnectionDatabaseCommand(BaseCommand):
|
||||||
engine=database.db_engine_spec.__name__,
|
engine=database.db_engine_spec.__name__,
|
||||||
)
|
)
|
||||||
# bubble up the exception to return a 400
|
# bubble up the exception to return a 400
|
||||||
raise ex
|
raise
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
event_logger.log_with_context(
|
event_logger.log_with_context(
|
||||||
action=get_log_connection_action(
|
action=get_log_connection_action(
|
||||||
|
|
|
||||||
|
|
@ -85,9 +85,9 @@ class UpdateDatabaseCommand(BaseCommand):
|
||||||
database.set_sqlalchemy_uri(database.sqlalchemy_uri)
|
database.set_sqlalchemy_uri(database.sqlalchemy_uri)
|
||||||
ssh_tunnel = self._handle_ssh_tunnel(database)
|
ssh_tunnel = self._handle_ssh_tunnel(database)
|
||||||
self._refresh_catalogs(database, original_database_name, ssh_tunnel)
|
self._refresh_catalogs(database, original_database_name, ssh_tunnel)
|
||||||
except SSHTunnelError as ex:
|
except SSHTunnelError: # pylint: disable=try-except-raise
|
||||||
# allow exception to bubble for debugbing information
|
# allow exception to bubble for debugbing information
|
||||||
raise ex
|
raise
|
||||||
except (DAOUpdateFailedError, DAOCreateFailedError) as ex:
|
except (DAOUpdateFailedError, DAOCreateFailedError) as ex:
|
||||||
raise DatabaseUpdateFailedError() from ex
|
raise DatabaseUpdateFailedError() from ex
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,14 +58,14 @@ class ImportDatasetsCommand(BaseCommand):
|
||||||
return
|
return
|
||||||
except IncorrectVersionError:
|
except IncorrectVersionError:
|
||||||
logger.debug("File not handled by command, skipping")
|
logger.debug("File not handled by command, skipping")
|
||||||
except (CommandInvalidError, ValidationError) as exc:
|
except (CommandInvalidError, ValidationError):
|
||||||
# found right version, but file is invalid
|
# found right version, but file is invalid
|
||||||
logger.info("Command failed validation")
|
logger.info("Command failed validation")
|
||||||
raise exc
|
raise
|
||||||
except Exception as exc:
|
except Exception:
|
||||||
# validation succeeded but something went wrong
|
# validation succeeded but something went wrong
|
||||||
logger.exception("Error running import command")
|
logger.exception("Error running import command")
|
||||||
raise exc
|
raise
|
||||||
|
|
||||||
raise CommandInvalidError("Could not find a valid command to import file")
|
raise CommandInvalidError("Could not find a valid command to import file")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,9 +74,9 @@ class ImportModelsCommand(BaseCommand):
|
||||||
try:
|
try:
|
||||||
self._import(self._configs, self.overwrite)
|
self._import(self._configs, self.overwrite)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
except CommandException as ex:
|
except CommandException:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
raise ex
|
raise
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
raise self.import_error() from ex
|
raise self.import_error() from ex
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ def load_metadata(contents: dict[str, str]) -> dict[str, str]:
|
||||||
|
|
||||||
# otherwise we raise the validation error
|
# otherwise we raise the validation error
|
||||||
ex.messages = {METADATA_FILE_NAME: ex.messages}
|
ex.messages = {METADATA_FILE_NAME: ex.messages}
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,10 +55,10 @@ class ImportSavedQueriesCommand(BaseCommand):
|
||||||
return
|
return
|
||||||
except IncorrectVersionError:
|
except IncorrectVersionError:
|
||||||
logger.debug("File not handled by command, skipping")
|
logger.debug("File not handled by command, skipping")
|
||||||
except (CommandInvalidError, ValidationError) as exc:
|
except (CommandInvalidError, ValidationError):
|
||||||
# found right version, but file is invalid
|
# found right version, but file is invalid
|
||||||
logger.exception("Error running import command")
|
logger.exception("Error running import command")
|
||||||
raise exc
|
raise
|
||||||
|
|
||||||
raise CommandInvalidError("Could not find a valid command to import file")
|
raise CommandInvalidError("Could not find a valid command to import file")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -599,7 +599,7 @@ class ReportNotTriggeredErrorState(BaseReportState):
|
||||||
self.update_report_schedule_and_log(
|
self.update_report_schedule_and_log(
|
||||||
ReportState.ERROR, error_message=second_error_message
|
ReportState.ERROR, error_message=second_error_message
|
||||||
)
|
)
|
||||||
raise first_ex
|
raise
|
||||||
|
|
||||||
|
|
||||||
class ReportWorkingState(BaseReportState):
|
class ReportWorkingState(BaseReportState):
|
||||||
|
|
@ -662,7 +662,7 @@ class ReportSuccessState(BaseReportState):
|
||||||
ReportState.ERROR,
|
ReportState.ERROR,
|
||||||
error_message=REPORT_SCHEDULE_ERROR_NOTIFICATION_MARKER,
|
error_message=REPORT_SCHEDULE_ERROR_NOTIFICATION_MARKER,
|
||||||
)
|
)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.send()
|
self.send()
|
||||||
|
|
@ -737,8 +737,8 @@ class AsyncExecuteReportScheduleCommand(BaseCommand):
|
||||||
ReportScheduleStateMachine(
|
ReportScheduleStateMachine(
|
||||||
self._execution_id, self._model, self._scheduled_dttm
|
self._execution_id, self._model, self._scheduled_dttm
|
||||||
).run()
|
).run()
|
||||||
except CommandException as ex:
|
except CommandException:
|
||||||
raise ex
|
raise
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise ReportScheduleUnexpectedError(str(ex)) from ex
|
raise ReportScheduleUnexpectedError(str(ex)) from ex
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class CreateRLSRuleCommand(BaseCommand):
|
||||||
return RLSDAO.create(attributes=self._properties)
|
return RLSDAO.create(attributes=self._properties)
|
||||||
except DAOCreateFailedError as ex:
|
except DAOCreateFailedError as ex:
|
||||||
logger.exception(ex.exception)
|
logger.exception(ex.exception)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
def validate(self) -> None:
|
def validate(self) -> None:
|
||||||
roles = populate_roles(self._roles)
|
roles = populate_roles(self._roles)
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class UpdateRLSRuleCommand(BaseCommand):
|
||||||
rule = RLSDAO.update(self._model, self._properties)
|
rule = RLSDAO.update(self._model, self._properties)
|
||||||
except DAOUpdateFailedError as ex:
|
except DAOUpdateFailedError as ex:
|
||||||
logger.exception(ex.exception)
|
logger.exception(ex.exception)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
return rule
|
return rule
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,10 +115,10 @@ class ExecuteSqlCommand(BaseCommand):
|
||||||
"status": status,
|
"status": status,
|
||||||
"payload": self._execution_context_convertor.serialize_payload(),
|
"payload": self._execution_context_convertor.serialize_payload(),
|
||||||
}
|
}
|
||||||
except (SupersetErrorException, SupersetErrorsException) as ex:
|
except (SupersetErrorException, SupersetErrorsException):
|
||||||
# to make sure we raising the original
|
# to make sure we raising the original
|
||||||
# SupersetErrorsException || SupersetErrorsException
|
# SupersetErrorsException || SupersetErrorsException
|
||||||
raise ex
|
raise
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise SqlLabException(self._execution_context, exception=ex) from ex
|
raise SqlLabException(self._execution_context, exception=ex) from ex
|
||||||
|
|
||||||
|
|
@ -158,9 +158,9 @@ class ExecuteSqlCommand(BaseCommand):
|
||||||
return self._sql_json_executor.execute(
|
return self._sql_json_executor.execute(
|
||||||
self._execution_context, rendered_query, self._log_params
|
self._execution_context, rendered_query, self._log_params
|
||||||
)
|
)
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
self._query_dao.update(query, {"status": QueryStatus.FAILED})
|
self._query_dao.update(query, {"status": QueryStatus.FAILED})
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
def _get_the_query_db(self) -> Database:
|
def _get_the_query_db(self) -> Database:
|
||||||
mydb: Any = self._database_dao.find_by_id(self._execution_context.database_id)
|
mydb: Any = self._database_dao.find_by_id(self._execution_context.database_id)
|
||||||
|
|
|
||||||
|
|
@ -276,7 +276,7 @@ class QueryObject: # pylint: disable=too-many-instance-attributes
|
||||||
return None
|
return None
|
||||||
except QueryObjectValidationError as ex:
|
except QueryObjectValidationError as ex:
|
||||||
if raise_exceptions:
|
if raise_exceptions:
|
||||||
raise ex
|
raise
|
||||||
return ex
|
return ex
|
||||||
|
|
||||||
def _validate_no_have_duplicate_labels(self) -> None:
|
def _validate_no_have_duplicate_labels(self) -> None:
|
||||||
|
|
|
||||||
|
|
@ -1727,11 +1727,11 @@ class SqlaTable(
|
||||||
self.schema or None,
|
self.schema or None,
|
||||||
mutator=assign_column_label,
|
mutator=assign_column_label,
|
||||||
)
|
)
|
||||||
except (SupersetErrorException, SupersetErrorsException) as ex:
|
except (SupersetErrorException, SupersetErrorsException):
|
||||||
# SupersetError(s) exception should not be captured; instead, they should
|
# SupersetError(s) exception should not be captured; instead, they should
|
||||||
# bubble up to the Flask error handler so they are returned as proper SIP-40
|
# bubble up to the Flask error handler so they are returned as proper SIP-40
|
||||||
# errors. This is particularly important for database OAuth2, see SIP-85.
|
# errors. This is particularly important for database OAuth2, see SIP-85.
|
||||||
raise ex
|
raise
|
||||||
except Exception as ex: # pylint: disable=broad-except
|
except Exception as ex: # pylint: disable=broad-except
|
||||||
# TODO (betodealmeida): review exception handling while querying the external
|
# TODO (betodealmeida): review exception handling while querying the external
|
||||||
# database. Ideally we'd expect and handle external database error, but
|
# database. Ideally we'd expect and handle external database error, but
|
||||||
|
|
|
||||||
|
|
@ -123,8 +123,8 @@ def make_url_safe(raw_url: str | URL) -> URL:
|
||||||
url = raw_url.strip()
|
url = raw_url.strip()
|
||||||
try:
|
try:
|
||||||
return make_url(url) # noqa
|
return make_url(url) # noqa
|
||||||
except Exception:
|
except Exception as ex:
|
||||||
raise DatabaseInvalidError() # pylint: disable=raise-missing-from
|
raise DatabaseInvalidError() from ex
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return raw_url
|
return raw_url
|
||||||
|
|
|
||||||
|
|
@ -2001,7 +2001,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||||
extra = json.loads(database.extra)
|
extra = json.loads(database.extra)
|
||||||
except json.JSONDecodeError as ex:
|
except json.JSONDecodeError as ex:
|
||||||
logger.error(ex, exc_info=True)
|
logger.error(ex, exc_info=True)
|
||||||
raise ex
|
raise
|
||||||
return extra
|
return extra
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
@ -2022,7 +2022,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||||
params.update(encrypted_extra)
|
params.update(encrypted_extra)
|
||||||
except json.JSONDecodeError as ex:
|
except json.JSONDecodeError as ex:
|
||||||
logger.error(ex, exc_info=True)
|
logger.error(ex, exc_info=True)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_readonly_query(cls, parsed_query: ParsedQuery) -> bool:
|
def is_readonly_query(cls, parsed_query: ParsedQuery) -> bool:
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ class ImpalaEngineSpec(BaseEngineSpec):
|
||||||
try:
|
try:
|
||||||
cursor.execute_async(query)
|
cursor.execute_async(query)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise cls.get_dbapi_mapped_exception(ex)
|
raise cls.get_dbapi_mapped_exception(ex) from ex
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def handle_cursor(cls, cursor: Any, query: Query) -> None:
|
def handle_cursor(cls, cursor: Any, query: Query) -> None:
|
||||||
|
|
|
||||||
|
|
@ -315,12 +315,12 @@ class OcientEngineSpec(BaseEngineSpec):
|
||||||
) -> list[tuple[Any, ...]]:
|
) -> list[tuple[Any, ...]]:
|
||||||
try:
|
try:
|
||||||
rows: list[tuple[Any, ...]] = super().fetch_data(cursor, limit)
|
rows: list[tuple[Any, ...]] = super().fetch_data(cursor, limit)
|
||||||
except Exception as exception:
|
except Exception:
|
||||||
with OcientEngineSpec.query_id_mapping_lock:
|
with OcientEngineSpec.query_id_mapping_lock:
|
||||||
del OcientEngineSpec.query_id_mapping[
|
del OcientEngineSpec.query_id_mapping[
|
||||||
getattr(cursor, "superset_query_id")
|
getattr(cursor, "superset_query_id")
|
||||||
]
|
]
|
||||||
raise exception
|
raise
|
||||||
|
|
||||||
# TODO: Unsure if we need to verify that we are receiving rows:
|
# TODO: Unsure if we need to verify that we are receiving rows:
|
||||||
if len(rows) > 0 and type(rows[0]).__name__ == "Row":
|
if len(rows) > 0 and type(rows[0]).__name__ == "Row":
|
||||||
|
|
|
||||||
|
|
@ -368,7 +368,7 @@ class SnowflakeEngineSpec(PostgresBaseEngineSpec):
|
||||||
encrypted_extra = json.loads(database.encrypted_extra)
|
encrypted_extra = json.loads(database.encrypted_extra)
|
||||||
except json.JSONDecodeError as ex:
|
except json.JSONDecodeError as ex:
|
||||||
logger.error(ex, exc_info=True)
|
logger.error(ex, exc_info=True)
|
||||||
raise ex
|
raise
|
||||||
auth_method = encrypted_extra.get("auth_method", None)
|
auth_method = encrypted_extra.get("auth_method", None)
|
||||||
auth_params = encrypted_extra.get("auth_params", {})
|
auth_params = encrypted_extra.get("auth_params", {})
|
||||||
if not auth_method:
|
if not auth_method:
|
||||||
|
|
|
||||||
|
|
@ -342,7 +342,7 @@ class TrinoEngineSpec(PrestoBaseEngineSpec):
|
||||||
connect_args["auth"] = trino_auth(**auth_params)
|
connect_args["auth"] = trino_auth(**auth_params)
|
||||||
except json.JSONDecodeError as ex:
|
except json.JSONDecodeError as ex:
|
||||||
logger.error(ex, exc_info=True)
|
logger.error(ex, exc_info=True)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_dbapi_exception_mapping(cls) -> dict[type[Exception], type[Exception]]:
|
def get_dbapi_exception_mapping(cls) -> dict[type[Exception], type[Exception]]:
|
||||||
|
|
|
||||||
|
|
@ -118,13 +118,13 @@ def compute_time_compare(granularity, periods):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj = isodate.parse_duration(granularity) * periods
|
obj = isodate.parse_duration(granularity) * periods
|
||||||
except isodate.isoerror.ISO8601Error:
|
except isodate.isoerror.ISO8601Error as ex:
|
||||||
# if parse_human_timedelta can parse it, return it directly
|
# if parse_human_timedelta can parse it, return it directly
|
||||||
delta = f"{periods} {granularity}{'s' if periods > 1 else ''}"
|
delta = f"{periods} {granularity}{'s' if periods > 1 else ''}"
|
||||||
obj = parse_human_timedelta(delta)
|
obj = parse_human_timedelta(delta)
|
||||||
if obj:
|
if obj:
|
||||||
return delta
|
return delta
|
||||||
raise Exception(f"Unable to parse: {granularity}")
|
raise Exception(f"Unable to parse: {granularity}") from ex
|
||||||
|
|
||||||
if isinstance(obj, isodate.duration.Duration):
|
if isinstance(obj, isodate.duration.Duration):
|
||||||
return isodate_duration_to_string(obj)
|
return isodate_duration_to_string(obj)
|
||||||
|
|
|
||||||
|
|
@ -197,9 +197,9 @@ def upgrade():
|
||||||
|
|
||||||
dashboard.json_metadata = json.dumps(json_metadata, sort_keys=True)
|
dashboard.json_metadata = json.dumps(json_metadata, sort_keys=True)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print(f"Parsing json_metadata for dashboard {dashboard.id} failed.")
|
print(f"Parsing json_metadata for dashboard {dashboard.id} failed.")
|
||||||
raise e
|
raise
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
@ -225,9 +225,9 @@ def downgrade():
|
||||||
changed_filter_sets += 1
|
changed_filter_sets += 1
|
||||||
changed_filters += downgrade_filter_set(filter_set)
|
changed_filters += downgrade_filter_set(filter_set)
|
||||||
dashboard.json_metadata = json.dumps(json_metadata, sort_keys=True)
|
dashboard.json_metadata = json.dumps(json_metadata, sort_keys=True)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print(f"Parsing json_metadata for dashboard {dashboard.id} failed.")
|
print(f"Parsing json_metadata for dashboard {dashboard.id} failed.")
|
||||||
raise e
|
raise
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
|
||||||
|
|
@ -111,9 +111,9 @@ def upgrade():
|
||||||
changed_filters += upgrades[0]
|
changed_filters += upgrades[0]
|
||||||
changed_filter_sets += upgrades[1]
|
changed_filter_sets += upgrades[1]
|
||||||
dashboard.json_metadata = json.dumps(json_metadata, sort_keys=True)
|
dashboard.json_metadata = json.dumps(json_metadata, sort_keys=True)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print(f"Parsing json_metadata for dashboard {dashboard.id} failed.")
|
print(f"Parsing json_metadata for dashboard {dashboard.id} failed.")
|
||||||
raise e
|
raise
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
@ -151,9 +151,9 @@ def downgrade():
|
||||||
changed_filters += downgrades[0]
|
changed_filters += downgrades[0]
|
||||||
changed_filter_sets += downgrades[1]
|
changed_filter_sets += downgrades[1]
|
||||||
dashboard.json_metadata = json.dumps(json_metadata, sort_keys=True)
|
dashboard.json_metadata = json.dumps(json_metadata, sort_keys=True)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print(f"Parsing json_metadata for dashboard {dashboard.id} failed.")
|
print(f"Parsing json_metadata for dashboard {dashboard.id} failed.")
|
||||||
raise e
|
raise
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
|
||||||
|
|
@ -92,9 +92,9 @@ def upgrade():
|
||||||
]
|
]
|
||||||
changed_slices += 1
|
changed_slices += 1
|
||||||
slice.params = json.dumps(params, sort_keys=True)
|
slice.params = json.dumps(params, sort_keys=True)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print(f"Parsing json_metadata for slice {slice.id} failed.")
|
print(f"Parsing json_metadata for slice {slice.id} failed.")
|
||||||
raise e
|
raise
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
|
||||||
|
|
@ -63,12 +63,12 @@ def upgrade():
|
||||||
if header_timestamp_format:
|
if header_timestamp_format:
|
||||||
params["time_format"] = header_timestamp_format
|
params["time_format"] = header_timestamp_format
|
||||||
slc.params = json.dumps(params, sort_keys=True)
|
slc.params = json.dumps(params, sort_keys=True)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
f"An error occurred: parsing params for slice {slc.id} failed."
|
f"An error occurred: parsing params for slice {slc.id} failed."
|
||||||
f"You need to fix it before upgrading your DB."
|
f"You need to fix it before upgrading your DB."
|
||||||
)
|
)
|
||||||
raise e
|
raise
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
@ -89,12 +89,12 @@ def downgrade():
|
||||||
if force_timestamp_formatting:
|
if force_timestamp_formatting:
|
||||||
params["header_format_selector"] = force_timestamp_formatting
|
params["header_format_selector"] = force_timestamp_formatting
|
||||||
slc.params = json.dumps(params, sort_keys=True)
|
slc.params = json.dumps(params, sort_keys=True)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
f"An error occurred: parsing params for slice {slc.id} failed. "
|
f"An error occurred: parsing params for slice {slc.id} failed. "
|
||||||
"You need to fix it before downgrading your DB."
|
"You need to fix it before downgrading your DB."
|
||||||
)
|
)
|
||||||
raise e
|
raise
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
|
||||||
|
|
@ -61,12 +61,12 @@ def upgrade():
|
||||||
if legacy_order_by:
|
if legacy_order_by:
|
||||||
params["series_limit_metric"] = legacy_order_by
|
params["series_limit_metric"] = legacy_order_by
|
||||||
slc.params = json.dumps(params, sort_keys=True)
|
slc.params = json.dumps(params, sort_keys=True)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
f"An error occurred: parsing params for slice {slc.id} failed."
|
f"An error occurred: parsing params for slice {slc.id} failed."
|
||||||
f"You need to fix it before upgrading your DB."
|
f"You need to fix it before upgrading your DB."
|
||||||
)
|
)
|
||||||
raise e
|
raise
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
@ -84,12 +84,12 @@ def downgrade():
|
||||||
if series_limit_metric:
|
if series_limit_metric:
|
||||||
params["legacy_order_by"] = series_limit_metric
|
params["legacy_order_by"] = series_limit_metric
|
||||||
slc.params = json.dumps(params, sort_keys=True)
|
slc.params = json.dumps(params, sort_keys=True)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
f"An error occurred: parsing params for slice {slc.id} failed. "
|
f"An error occurred: parsing params for slice {slc.id} failed. "
|
||||||
"You need to fix it before downgrading your DB."
|
"You need to fix it before downgrading your DB."
|
||||||
)
|
)
|
||||||
raise e
|
raise
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
|
||||||
|
|
@ -90,9 +90,9 @@ def upgrade():
|
||||||
if needs_upgrade:
|
if needs_upgrade:
|
||||||
dashboard.json_metadata = json.dumps(json_metadata)
|
dashboard.json_metadata = json.dumps(json_metadata)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.exception("Failed to run up migration")
|
logger.exception("Failed to run up migration")
|
||||||
raise e
|
raise
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
@ -127,9 +127,9 @@ def downgrade():
|
||||||
|
|
||||||
dashboard.json_metadata = json.dumps(json_metadata)
|
dashboard.json_metadata = json.dumps(json_metadata)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.exception("Failed to run down migration")
|
logger.exception("Failed to run down migration")
|
||||||
raise e
|
raise
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ def upgrade():
|
||||||
session.commit()
|
session.commit()
|
||||||
except SQLAlchemyError as ex:
|
except SQLAlchemyError as ex:
|
||||||
session.rollback()
|
session.rollback()
|
||||||
raise Exception(f"An error occurred while upgrading permissions: {ex}")
|
raise Exception(f"An error occurred while upgrading permissions: {ex}") from ex
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ def upgrade():
|
||||||
session.commit()
|
session.commit()
|
||||||
except SQLAlchemyError as ex:
|
except SQLAlchemyError as ex:
|
||||||
session.rollback()
|
session.rollback()
|
||||||
raise Exception(f"An error occurred while upgrading permissions: {ex}")
|
raise Exception(f"An error occurred while upgrading permissions: {ex}") from ex
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ def upgrade():
|
||||||
session.commit()
|
session.commit()
|
||||||
except SQLAlchemyError as ex:
|
except SQLAlchemyError as ex:
|
||||||
session.rollback()
|
session.rollback()
|
||||||
raise Exception(f"An error occurred while upgrading permissions: {ex}")
|
raise Exception(f"An error occurred while upgrading permissions: {ex}") from ex
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ def upgrade():
|
||||||
session.commit()
|
session.commit()
|
||||||
except SQLAlchemyError as ex:
|
except SQLAlchemyError as ex:
|
||||||
session.rollback()
|
session.rollback()
|
||||||
raise Exception(f"An error occurred while upgrading permissions: {ex}")
|
raise Exception(f"An error occurred while upgrading permissions: {ex}") from ex
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ def upgrade():
|
||||||
f"An error occurred: Upgrading params for slice {slc.id} failed."
|
f"An error occurred: Upgrading params for slice {slc.id} failed."
|
||||||
f"You need to fix it before upgrading your DB."
|
f"You need to fix it before upgrading your DB."
|
||||||
)
|
)
|
||||||
raise Exception(f"An error occurred while upgrading slice: {ex}")
|
raise Exception(f"An error occurred while upgrading slice: {ex}") from ex
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
@ -206,7 +206,7 @@ def downgrade():
|
||||||
f"An error occurred: Downgrading params for slice {slc.id} failed."
|
f"An error occurred: Downgrading params for slice {slc.id} failed."
|
||||||
f"You need to fix it before downgrading your DB."
|
f"You need to fix it before downgrading your DB."
|
||||||
)
|
)
|
||||||
raise Exception(f"An error occurred while downgrading slice: {ex}")
|
raise Exception(f"An error occurred while downgrading slice: {ex}") from ex
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
|
||||||
|
|
@ -538,7 +538,7 @@ class Database(Model, AuditMixinNullable, ImportExportMixin): # pylint: disable
|
||||||
try:
|
try:
|
||||||
return create_engine(sqlalchemy_url, **params)
|
return create_engine(sqlalchemy_url, **params)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise self.db_engine_spec.get_dbapi_mapped_exception(ex)
|
raise self.db_engine_spec.get_dbapi_mapped_exception(ex) from ex
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def get_raw_connection(
|
def get_raw_connection(
|
||||||
|
|
@ -570,7 +570,7 @@ class Database(Model, AuditMixinNullable, ImportExportMixin): # pylint: disable
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
if self.is_oauth2_enabled() and self.db_engine_spec.needs_oauth2(ex):
|
if self.is_oauth2_enabled() and self.db_engine_spec.needs_oauth2(ex):
|
||||||
self.db_engine_spec.start_oauth2_dance(self)
|
self.db_engine_spec.start_oauth2_dance(self)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
def get_default_catalog(self) -> str | None:
|
def get_default_catalog(self) -> str | None:
|
||||||
"""
|
"""
|
||||||
|
|
@ -769,7 +769,7 @@ class Database(Model, AuditMixinNullable, ImportExportMixin): # pylint: disable
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise self.db_engine_spec.get_dbapi_mapped_exception(ex)
|
raise self.db_engine_spec.get_dbapi_mapped_exception(ex) from ex
|
||||||
|
|
||||||
@cache_util.memoized_func(
|
@cache_util.memoized_func(
|
||||||
key="db:{self.id}:schema:{schema}:view_list",
|
key="db:{self.id}:schema:{schema}:view_list",
|
||||||
|
|
@ -803,7 +803,7 @@ class Database(Model, AuditMixinNullable, ImportExportMixin): # pylint: disable
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise self.db_engine_spec.get_dbapi_mapped_exception(ex)
|
raise self.db_engine_spec.get_dbapi_mapped_exception(ex) from ex
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def get_inspector(
|
def get_inspector(
|
||||||
|
|
@ -906,7 +906,7 @@ class Database(Model, AuditMixinNullable, ImportExportMixin): # pylint: disable
|
||||||
encrypted_extra = json.loads(self.encrypted_extra)
|
encrypted_extra = json.loads(self.encrypted_extra)
|
||||||
except json.JSONDecodeError as ex:
|
except json.JSONDecodeError as ex:
|
||||||
logger.error(ex, exc_info=True)
|
logger.error(ex, exc_info=True)
|
||||||
raise ex
|
raise
|
||||||
return encrypted_extra
|
return encrypted_extra
|
||||||
|
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
|
|
|
||||||
|
|
@ -310,7 +310,7 @@ class ImportExportMixin:
|
||||||
try:
|
try:
|
||||||
obj_query = db.session.query(cls).filter(and_(*filters))
|
obj_query = db.session.query(cls).filter(and_(*filters))
|
||||||
obj = obj_query.one_or_none()
|
obj = obj_query.one_or_none()
|
||||||
except MultipleResultsFound as ex:
|
except MultipleResultsFound:
|
||||||
logger.error(
|
logger.error(
|
||||||
"Error importing %s \n %s \n %s",
|
"Error importing %s \n %s \n %s",
|
||||||
cls.__name__,
|
cls.__name__,
|
||||||
|
|
@ -318,7 +318,7 @@ class ImportExportMixin:
|
||||||
yaml.safe_dump(dict_rep),
|
yaml.safe_dump(dict_rep),
|
||||||
exc_info=True,
|
exc_info=True,
|
||||||
)
|
)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
if not obj:
|
if not obj:
|
||||||
is_new_obj = True
|
is_new_obj = True
|
||||||
|
|
|
||||||
|
|
@ -312,9 +312,9 @@ def execute_sql_statement( # pylint: disable=too-many-statements
|
||||||
level=ErrorLevel.ERROR,
|
level=ErrorLevel.ERROR,
|
||||||
)
|
)
|
||||||
) from ex
|
) from ex
|
||||||
except OAuth2RedirectError as ex:
|
except OAuth2RedirectError:
|
||||||
# user needs to authenticate with OAuth2 in order to run query
|
# user needs to authenticate with OAuth2 in order to run query
|
||||||
raise ex
|
raise
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
# query is stopped in another thread/worker
|
# query is stopped in another thread/worker
|
||||||
# stopping raises expected exceptions which we should skip
|
# stopping raises expected exceptions which we should skip
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ class PrestoDBSQLValidator(BaseSQLValidator):
|
||||||
)
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.exception("Unexpected error running validation query: %s", str(ex))
|
logger.exception("Unexpected error running validation query: %s", str(ex))
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate(
|
def validate(
|
||||||
|
|
|
||||||
|
|
@ -97,8 +97,8 @@ class SynchronousSqlJsonExecutor(SqlJsonExecutorBase):
|
||||||
)
|
)
|
||||||
self._query_dao.update_saved_query_exec_info(query_id)
|
self._query_dao.update_saved_query_exec_info(query_id)
|
||||||
execution_context.set_execution_result(data)
|
execution_context.set_execution_result(data)
|
||||||
except SupersetTimeoutException as ex:
|
except SupersetTimeoutException:
|
||||||
raise ex
|
raise
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.exception("Query %i failed unexpectedly", query_id)
|
logger.exception("Query %i failed unexpectedly", query_id)
|
||||||
raise SupersetGenericDBErrorException(
|
raise SupersetGenericDBErrorException(
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,9 @@ def _create_query_context_from_form(form_data: dict[str, Any]) -> QueryContext:
|
||||||
return ChartDataQueryContextSchema().load(form_data)
|
return ChartDataQueryContextSchema().load(form_data)
|
||||||
except KeyError as ex:
|
except KeyError as ex:
|
||||||
raise ValidationError("Request is incorrect") from ex
|
raise ValidationError("Request is incorrect") from ex
|
||||||
except ValidationError as error:
|
except ValidationError: # pylint: disable=try-except-raise
|
||||||
raise error
|
# Make sure to bubble this up
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
def _load_user_from_job_metadata(job_metadata: dict[str, Any]) -> User:
|
def _load_user_from_job_metadata(job_metadata: dict[str, Any]) -> User:
|
||||||
|
|
@ -96,7 +97,7 @@ def load_chart_data_into_cache(
|
||||||
)
|
)
|
||||||
except SoftTimeLimitExceeded as ex:
|
except SoftTimeLimitExceeded as ex:
|
||||||
logger.warning("A timeout occurred while loading chart data, error: %s", ex)
|
logger.warning("A timeout occurred while loading chart data, error: %s", ex)
|
||||||
raise ex
|
raise
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
# TODO: QueryContext should support SIP-40 style errors
|
# TODO: QueryContext should support SIP-40 style errors
|
||||||
error = str(ex.message if hasattr(ex, "message") else ex)
|
error = str(ex.message if hasattr(ex, "message") else ex)
|
||||||
|
|
@ -104,7 +105,7 @@ def load_chart_data_into_cache(
|
||||||
async_query_manager.update_job(
|
async_query_manager.update_job(
|
||||||
job_metadata, async_query_manager.STATUS_ERROR, errors=errors
|
job_metadata, async_query_manager.STATUS_ERROR, errors=errors
|
||||||
)
|
)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
|
|
||||||
@celery_app.task(name="load_explore_json_into_cache", soft_time_limit=query_timeout)
|
@celery_app.task(name="load_explore_json_into_cache", soft_time_limit=query_timeout)
|
||||||
|
|
@ -162,7 +163,7 @@ def load_explore_json_into_cache( # pylint: disable=too-many-locals
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"A timeout occurred while loading explore json, error: %s", ex
|
"A timeout occurred while loading explore json, error: %s", ex
|
||||||
)
|
)
|
||||||
raise ex
|
raise
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
if isinstance(ex, SupersetVizException):
|
if isinstance(ex, SupersetVizException):
|
||||||
errors = ex.errors
|
errors = ex.errors
|
||||||
|
|
@ -173,4 +174,4 @@ def load_explore_json_into_cache( # pylint: disable=too-many-locals
|
||||||
async_query_manager.update_job(
|
async_query_manager.update_job(
|
||||||
job_metadata, async_query_manager.STATUS_ERROR, errors=errors
|
job_metadata, async_query_manager.STATUS_ERROR, errors=errors
|
||||||
)
|
)
|
||||||
raise ex
|
raise
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ def statsd_gauge(metric_prefix: str | None = None) -> Callable[..., Any]:
|
||||||
current_app.config["STATS_LOGGER"].gauge(
|
current_app.config["STATS_LOGGER"].gauge(
|
||||||
f"{metric_prefix_}.error", 1
|
f"{metric_prefix_}.error", 1
|
||||||
)
|
)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
@ -146,8 +146,9 @@ def stats_timing(stats_key: str, stats_logger: BaseStatsLogger) -> Iterator[floa
|
||||||
start_ts = now_as_float()
|
start_ts = now_as_float()
|
||||||
try:
|
try:
|
||||||
yield start_ts
|
yield start_ts
|
||||||
except Exception as ex:
|
except Exception: # pylint: disable=try-except-raise
|
||||||
raise ex
|
# Make sure to bubble this up
|
||||||
|
raise
|
||||||
finally:
|
finally:
|
||||||
stats_logger.timing(stats_key, now_as_float() - start_ts)
|
stats_logger.timing(stats_key, now_as_float() - start_ts)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,11 +122,11 @@ def json_iso_dttm_ser(obj: Any, pessimistic: bool = False) -> Any:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return base_json_conv(obj)
|
return base_json_conv(obj)
|
||||||
except TypeError as ex:
|
except TypeError:
|
||||||
if pessimistic:
|
if pessimistic:
|
||||||
logger.error("Failed to serialize %s", obj)
|
logger.error("Failed to serialize %s", obj)
|
||||||
return f"Unserializable [{type(obj)}]"
|
return f"Unserializable [{type(obj)}]"
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
|
|
||||||
def pessimistic_json_iso_dttm_ser(obj: Any) -> Any:
|
def pessimistic_json_iso_dttm_ser(obj: Any) -> Any:
|
||||||
|
|
@ -249,4 +249,4 @@ def loads(
|
||||||
)
|
)
|
||||||
except JSONDecodeError as ex:
|
except JSONDecodeError as ex:
|
||||||
logger.error("JSON is not valid %s", str(ex), exc_info=True)
|
logger.error("JSON is not valid %s", str(ex), exc_info=True)
|
||||||
raise ex
|
raise
|
||||||
|
|
|
||||||
|
|
@ -180,9 +180,9 @@ class WebDriverPlaywright(WebDriverProxy):
|
||||||
)
|
)
|
||||||
element = page.locator(f".{element_name}")
|
element = page.locator(f".{element_name}")
|
||||||
element.wait_for()
|
element.wait_for()
|
||||||
except PlaywrightTimeout as ex:
|
except PlaywrightTimeout:
|
||||||
logger.exception("Timed out requesting url %s", url)
|
logger.exception("Timed out requesting url %s", url)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# chart containers didn't render
|
# chart containers didn't render
|
||||||
|
|
@ -191,12 +191,12 @@ class WebDriverPlaywright(WebDriverProxy):
|
||||||
slice_container_locator.first.wait_for()
|
slice_container_locator.first.wait_for()
|
||||||
for slice_container_elem in slice_container_locator.all():
|
for slice_container_elem in slice_container_locator.all():
|
||||||
slice_container_elem.wait_for()
|
slice_container_elem.wait_for()
|
||||||
except PlaywrightTimeout as ex:
|
except PlaywrightTimeout:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
"Timed out waiting for chart containers to draw at url %s",
|
"Timed out waiting for chart containers to draw at url %s",
|
||||||
url,
|
url,
|
||||||
)
|
)
|
||||||
raise ex
|
raise
|
||||||
try:
|
try:
|
||||||
# charts took too long to load
|
# charts took too long to load
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
|
@ -204,11 +204,11 @@ class WebDriverPlaywright(WebDriverProxy):
|
||||||
)
|
)
|
||||||
for loading_element in page.locator(".loading").all():
|
for loading_element in page.locator(".loading").all():
|
||||||
loading_element.wait_for(state="detached")
|
loading_element.wait_for(state="detached")
|
||||||
except PlaywrightTimeout as ex:
|
except PlaywrightTimeout:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
"Timed out waiting for charts to load at url %s", url
|
"Timed out waiting for charts to load at url %s", url
|
||||||
)
|
)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
selenium_animation_wait = current_app.config[
|
selenium_animation_wait = current_app.config[
|
||||||
"SCREENSHOT_SELENIUM_ANIMATION_WAIT"
|
"SCREENSHOT_SELENIUM_ANIMATION_WAIT"
|
||||||
|
|
@ -366,9 +366,9 @@ class WebDriverSelenium(WebDriverProxy):
|
||||||
element = WebDriverWait(driver, self._screenshot_locate_wait).until(
|
element = WebDriverWait(driver, self._screenshot_locate_wait).until(
|
||||||
EC.presence_of_element_located((By.CLASS_NAME, element_name))
|
EC.presence_of_element_located((By.CLASS_NAME, element_name))
|
||||||
)
|
)
|
||||||
except TimeoutException as ex:
|
except TimeoutException:
|
||||||
logger.exception("Selenium timed out requesting url %s", url)
|
logger.exception("Selenium timed out requesting url %s", url)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# chart containers didn't render
|
# chart containers didn't render
|
||||||
|
|
@ -378,12 +378,12 @@ class WebDriverSelenium(WebDriverProxy):
|
||||||
(By.CLASS_NAME, "chart-container")
|
(By.CLASS_NAME, "chart-container")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except TimeoutException as ex:
|
except TimeoutException:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
"Selenium timed out waiting for chart containers to draw at url %s",
|
"Selenium timed out waiting for chart containers to draw at url %s",
|
||||||
url,
|
url,
|
||||||
)
|
)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# charts took too long to load
|
# charts took too long to load
|
||||||
|
|
@ -393,11 +393,11 @@ class WebDriverSelenium(WebDriverProxy):
|
||||||
WebDriverWait(driver, self._screenshot_load_wait).until_not(
|
WebDriverWait(driver, self._screenshot_load_wait).until_not(
|
||||||
EC.presence_of_all_elements_located((By.CLASS_NAME, "loading"))
|
EC.presence_of_all_elements_located((By.CLASS_NAME, "loading"))
|
||||||
)
|
)
|
||||||
except TimeoutException as ex:
|
except TimeoutException:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
"Selenium timed out waiting for charts to load at url %s", url
|
"Selenium timed out waiting for charts to load at url %s", url
|
||||||
)
|
)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
selenium_animation_wait = current_app.config[
|
selenium_animation_wait = current_app.config[
|
||||||
"SCREENSHOT_SELENIUM_ANIMATION_WAIT"
|
"SCREENSHOT_SELENIUM_ANIMATION_WAIT"
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ def statsd_metrics(f: Callable[..., Any]) -> Callable[..., Any]:
|
||||||
self.incr_stats("warning", func_name)
|
self.incr_stats("warning", func_name)
|
||||||
else:
|
else:
|
||||||
self.incr_stats("error", func_name)
|
self.incr_stats("error", func_name)
|
||||||
raise ex
|
raise
|
||||||
|
|
||||||
self.send_stats_metrics(response, func_name, duration)
|
self.send_stats_metrics(response, func_name, duration)
|
||||||
return response
|
return response
|
||||||
|
|
|
||||||
|
|
@ -198,15 +198,15 @@ def delete_all_inserted_dashboards():
|
||||||
for dashboard in dashboards_to_delete:
|
for dashboard in dashboards_to_delete:
|
||||||
try:
|
try:
|
||||||
delete_dashboard(dashboard, False)
|
delete_dashboard(dashboard, False)
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
logger.error(f"failed to delete {dashboard.id}", exc_info=True)
|
logger.error(f"failed to delete {dashboard.id}", exc_info=True)
|
||||||
raise ex
|
raise
|
||||||
if len(inserted_dashboards_ids) > 0:
|
if len(inserted_dashboards_ids) > 0:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
inserted_dashboards_ids.clear()
|
inserted_dashboards_ids.clear()
|
||||||
except Exception as ex2:
|
except Exception:
|
||||||
logger.error("delete_all_inserted_dashboards failed", exc_info=True)
|
logger.error("delete_all_inserted_dashboards failed", exc_info=True)
|
||||||
raise ex2
|
raise
|
||||||
|
|
||||||
|
|
||||||
def delete_dashboard(dashboard: Dashboard, do_commit: bool = False) -> None:
|
def delete_dashboard(dashboard: Dashboard, do_commit: bool = False) -> None:
|
||||||
|
|
@ -245,15 +245,15 @@ def delete_all_inserted_slices():
|
||||||
for slice in slices_to_delete:
|
for slice in slices_to_delete:
|
||||||
try:
|
try:
|
||||||
delete_slice(slice, False)
|
delete_slice(slice, False)
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
logger.error(f"failed to delete {slice.id}", exc_info=True)
|
logger.error(f"failed to delete {slice.id}", exc_info=True)
|
||||||
raise ex
|
raise
|
||||||
if len(inserted_slices_ids) > 0:
|
if len(inserted_slices_ids) > 0:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
inserted_slices_ids.clear()
|
inserted_slices_ids.clear()
|
||||||
except Exception as ex2:
|
except Exception:
|
||||||
logger.error("delete_all_inserted_slices failed", exc_info=True)
|
logger.error("delete_all_inserted_slices failed", exc_info=True)
|
||||||
raise ex2
|
raise
|
||||||
|
|
||||||
|
|
||||||
def delete_slice(slice_: Slice, do_commit: bool = False) -> None:
|
def delete_slice(slice_: Slice, do_commit: bool = False) -> None:
|
||||||
|
|
@ -278,15 +278,15 @@ def delete_all_inserted_tables():
|
||||||
for table in tables_to_delete:
|
for table in tables_to_delete:
|
||||||
try:
|
try:
|
||||||
delete_sqltable(table, False)
|
delete_sqltable(table, False)
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
logger.error(f"failed to delete {table.id}", exc_info=True)
|
logger.error(f"failed to delete {table.id}", exc_info=True)
|
||||||
raise ex
|
raise
|
||||||
if len(inserted_sqltables_ids) > 0:
|
if len(inserted_sqltables_ids) > 0:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
inserted_sqltables_ids.clear()
|
inserted_sqltables_ids.clear()
|
||||||
except Exception as ex2:
|
except Exception:
|
||||||
logger.error("delete_all_inserted_tables failed", exc_info=True)
|
logger.error("delete_all_inserted_tables failed", exc_info=True)
|
||||||
raise ex2
|
raise
|
||||||
|
|
||||||
|
|
||||||
def delete_sqltable(table: SqlaTable, do_commit: bool = False) -> None:
|
def delete_sqltable(table: SqlaTable, do_commit: bool = False) -> None:
|
||||||
|
|
@ -313,15 +313,15 @@ def delete_all_inserted_dbs():
|
||||||
for database in databases_to_delete:
|
for database in databases_to_delete:
|
||||||
try:
|
try:
|
||||||
delete_database(database, False)
|
delete_database(database, False)
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
logger.error(f"failed to delete {database.id}", exc_info=True)
|
logger.error(f"failed to delete {database.id}", exc_info=True)
|
||||||
raise ex
|
raise
|
||||||
if len(inserted_databases_ids) > 0:
|
if len(inserted_databases_ids) > 0:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
inserted_databases_ids.clear()
|
inserted_databases_ids.clear()
|
||||||
except Exception as ex2:
|
except Exception:
|
||||||
logger.error("delete_all_inserted_databases failed", exc_info=True)
|
logger.error("delete_all_inserted_databases failed", exc_info=True)
|
||||||
raise ex2
|
raise
|
||||||
|
|
||||||
|
|
||||||
def delete_database(database: Database, do_commit: bool = False) -> None:
|
def delete_database(database: Database, do_commit: bool = False) -> None:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue