GitHub user dosubot[bot] added a comment to the discussion: Show friendly error when Superset unable to connect to backing database
<!-- Answer --> That's an interesting finding. According to the code, virtual and physical datasets go through the **same error handling path** in `SqlaTable.query()` — both use `db_engine_spec.extract_errors(ex)` and `error_msg_from_exception(ex)` identically [[1]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/connectors/sqla/models.py#L1750-L1763). There's no conditional logic that treats them differently for error handling. The likely reason your monkey-patch works for physical datasets but not virtual ones is an **import ordering issue**. The function `error_msg_from_exception` may have already been imported by reference (e.g., `from superset.utils.core import error_msg_from_exception`) in certain modules before `FLASK_APP_MUTATOR` runs, so your patched version isn't used in all code paths. To address this, try patching at **multiple levels** in your `FLASK_APP_MUTATOR`: ```python def FLASK_APP_MUTATOR(app): import re from superset.utils import core as utils_core from superset.connectors.sqla import models as sqla_models _original = utils_core.error_msg_from_exception def sanitized_error_msg(ex): msg = _original(ex) if re.search( r"(connection to server|OperationalError|password authentication failed)", str(msg), re.IGNORECASE ): return "Unable to connect to the database. Please reach out to the Chart Owner for assistance." return msg # Patch at the module level AND anywhere it's been imported directly utils_core.error_msg_from_exception = sanitized_error_msg # Also patch it where it's used in the connectors module if hasattr(sqla_models, 'utils'): sqla_models.utils.error_msg_from_exception = sanitized_error_msg ``` Alternatively, a more reliable approach is to patch the **`extract_errors`** method on the engine spec class itself, since that's called by reference on the class: ```python def FLASK_APP_MUTATOR(app): import re from superset.db_engine_specs.postgres import PostgresEngineSpec _original_extract = PostgresEngineSpec.extract_errors @classmethod def sanitized_extract_errors(cls, ex): from superset.errors import SupersetError, SupersetErrorType, ErrorLevel msg = str(ex) if re.search(r"(connection to server|OperationalError|password authentication)", msg, re.IGNORECASE): return [SupersetError( message="Unable to connect to the database. Please reach out to the Chart Owner for assistance.", error_type=SupersetErrorType.CONNECTION_DATABASE_ERROR, level=ErrorLevel.ERROR, extra={"engine_name": "PostgreSQL"}, )] return _original_extract.__func__(cls, ex) PostgresEngineSpec.extract_errors = sanitized_extract_errors ``` This patches the class method directly, so regardless of how it's imported or called, both virtual and physical datasets will hit the patched version. Could you share the exact raw error you're seeing for the virtual dataset case? It might reveal whether the error is coming through a slightly different exception type or code path that I can help you target more precisely. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).* --- Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fsuperset). [](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fsuperset&message_id=f54a7f79-fa7b-4914-89f7-df2996d3ae83) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fsuperset) GitHub link: https://github.com/apache/superset/discussions/40881#discussioncomment-17275206 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
