Open OldrichDlouhy opened 2 weeks ago
Hello, @OldrichDlouhy! I'm here to help you with your bug report. If you need assistance with anything else, feel free to ask.
I found a similar issue related to a "500 - Internal Server Error" during dashboard import, which was caused by a CommandInvalidError
. The solution involves ensuring proper error handling and mapping the error to a SupersetErrorException
or SupersetErrorsException
with a specific status code and error type.
To address the HTML code leakage and improve error handling:
Validation: Ensure the metadata and configurations are correct. The validate
method in ImportAssetsCommand
checks these and raises CommandInvalidError
if there are issues.
Error Handling: Use the error handler for CommandException
to log the error and return a JSON error response. If the error is a CommandInvalidError
, include additional normalized messages in the response.
Here's a snippet for handling the error:
@app.errorhandler(CommandException)
def show_command_errors(ex: CommandException) -> FlaskResponse:
logger.warning("CommandException", exc_info=True)
if "text/html" in request.accept_mimetypes and not app.config["DEBUG"]:
path = files("superset") / "static/assets/500.html"
return send_file(path, max_age=0), 500
extra = ex.normalized_messages() if isinstance(ex, CommandInvalidError) else {}
return json_error_response(
[
SupersetError(
message=ex.message,
error_type=SupersetErrorType.GENERIC_COMMAND_ERROR,
level=get_error_level_from_status(ex.status),
extra=extra,
),
],
status=ex.status,
)
Ensure this handler is set up in your Flask app to catch and process CommandInvalidError
exceptions, providing a more informative error response [1][2].
To continue talking to Dosu, mention @dosu.
Had a similar issue using superset on Yunohost. This helpmed troubleshoot the error for me.
index f90708acf5..2fd0579a0f 100644
--- a/superset/commands/importers/v1/__init__.py
+++ b/superset/commands/importers/v1/__init__.py
@@ -104,6 +104,8 @@ class ImportModelsCommand(BaseCommand):
self._prevent_overwrite_existing_model(exceptions)
if exceptions:
+ import sys
+ print('NEEDLE',exceptions,file=sys.stderr)
raise CommandInvalidError(
f"Error importing {self.model_name}",
exceptions,
Printing the exceptions that are otherwise invislble allowed me to see what was causing the import error (invalid data in the exported yaml file). As stderr
is routed towards the service output it's viewable in the logs in yunohost.
It's not a solution, but solved my most urgend problem. Hope it helps someone else.
Bug description
When importing dashboard and the import fails, the error displayed is leaking HTML code of error page.
It seems there is other exception thrown when the import exception is processed.
Screenshots/recordings
Superset version
4.0.2
Python version
3.9
Node version
16
Browser
Chrome
Additional context
Extracted stacktrace from the displayed message:
Checklist