bito-code-review[bot] commented on code in PR #39964:
URL: https://github.com/apache/superset/pull/39964#discussion_r3207576034
##########
superset/mcp_service/chart/compile.py:
##########
@@ -278,6 +322,53 @@ def _validate_adhoc_filter_columns(
)
+def _classify_as_database_error(exc: BaseException, dataset_id: int) -> bool:
+ """Use the dataset's DB engine spec to classify the error.
+
+ Walks the ``__cause__`` chain for direct ``SQLAlchemyError`` instances,
+ then falls back to the engine spec's ``extract_errors`` regex patterns —
+ the same classification the Superset UI uses.
+ """
+ # Direct SQLAlchemy errors (unwrapped or in cause chain)
+ current: BaseException | None = exc
+ while current is not None:
+ if isinstance(current, SQLAlchemyError):
+ return True
+ current = current.__cause__
+
+ # Use the dataset's engine spec to classify (same as the UI)
+ try:
+ from superset.daos.dataset import DatasetDAO
+
+ dataset = DatasetDAO.find_by_id(dataset_id)
+ if dataset and dataset.database and isinstance(exc, Exception):
+ errors = dataset.database.db_engine_spec.extract_errors(exc)
+ return any(e.error_type in _CONNECTION_ERROR_TYPES for e in errors)
+ except Exception: # pylint: disable=broad-except
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Overly broad exception catch blocks</b></div>
<div id="fix">
Line 347 catches bare `Exception` which is too broad. Catch specific
exception types instead (e.g., `AttributeError`, `KeyError`, `TypeError`) to
avoid masking unexpected errors.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
except (AttributeError, KeyError, TypeError):
````
</div>
</details>
</div>
<small><i>Code Review Run #487b42</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]