bito-code-review[bot] commented on code in PR #42929:
URL: https://github.com/apache/superset/pull/42929#discussion_r3742451331
##########
superset/models/helpers.py:
##########
@@ -3020,9 +3080,40 @@ def get_from_clause(
if rls_applied:
from_sql = parsed_script.format()
- except Exception as ex:
- # Log the error but don't fail - RLS application is best-effort
- logger.warning("Failed to apply RLS to virtual dataset SQL:
%s", ex)
+ except Exception as ex: # pylint: disable=broad-except
+ # RLS injection failures fail closed: only continue when it is
+ # positively confirmed that no RLS predicates apply to the
+ # referenced tables; any other outcome aborts the query.
+ try:
+ rls_required = any(
+ get_predicates_for_table(
+ table.qualify(
+ catalog=self.catalog,
+ schema=self.schema or default_schema or "",
+ ),
+ self.database,
+ self.database.get_default_catalog(),
+ exclude_dataset_id=self_id,
+ )
+ for statement in parsed_script.statements
+ for table in statement.tables
+ )
+ except Exception: # pylint: disable=broad-except
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Broad exception clause detected</b></div>
<div id="fix">
Catching broad `Exception` is discouraged. Consider catching specific
exceptions like `ValueError` or using `ExceptionGroup` to preserve exception
context.
</div>
</div>
<small><i>Code Review Run #2ce454</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
##########
superset/commands/report/exceptions.py:
##########
@@ -40,6 +40,38 @@ def __init__(self) -> None:
super().__init__(_("Database does not exist"), field_name="database")
+class AlertQueryMultipleStatementsValidationError(ValidationError):
+ """
+ Marshmallow validation error for alert SQL containing multiple statements
+ """
+
+ def __init__(self) -> None:
+ super().__init__(
+ _("Alert query must be a single statement"),
+ field_name="sql",
+ )
+
+
+class AlertQueryDMLNotAllowedValidationError(ValidationError):
+ """
+ Marshmallow validation error for alert SQL that mutates state on a
+ database that does not allow DML
+ """
+
+ def __init__(self) -> None:
+ super().__init__(_("Alert query must be read-only"), field_name="sql")
+
+
+class AlertQueryDataAccessValidationError(ValidationError):
+ """
+ Marshmallow validation error for alert SQL referencing tables the user
+ is not authorized to query
+ """
+
+ def __init__(self, message: str) -> None:
+ super().__init__(message, field_name="sql")
+
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing test coverage for exceptions</b></div>
<div id="fix">
The new exception classes `AlertQueryDMLNotAllowedValidationError` (line 55)
and `AlertQueryDataAccessValidationError` (line 65) are used in
`validate_alert_query` (base.py:99-105) but have no unit test coverage. Add
tests for: (1) DML statement on database with `allow_dml=False`, (2) SQL
accessing unauthorized tables via `security_manager.raise_for_access`.
</div>
</div>
<small><i>Code Review Run #2ce454</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
##########
tests/unit_tests/connectors/sqla/models_test.py:
##########
@@ -1486,6 +1486,33 @@ def
test_validate_stored_expression_rejects_subquery_around_jinja(
)
+def test_get_sqla_col_revalidates_rendered_jinja_expression(
+ mocker: MockerFixture,
+) -> None:
+ """
+ A Jinja block that renders into a sub-query must be rejected at query
+ time: save-time validation only sees the block as a placeholder, so the
+ rendered expression is re-validated before it is embedded via
+ ``literal_column``.
+ """
+ # A real Database (not a MagicMock) so the ORM relationship assignment on
+ # SqlaTable has a valid instance state; sqlite gives a concrete backend.
+ database = Database(database_name="t", sqlalchemy_uri="sqlite://")
+ mocker.patch("superset.models.helpers.is_feature_enabled",
return_value=False)
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Wrong mock target in security test</b></div>
<div id="fix">
The mock at line 1501 patches `superset.models.helpers.is_feature_enabled`,
but `validate_rendered_expression` reads `is_feature_enabled` via
`superset.connectors.sqla.models` (module-level import). The mock is a dead
intercept and does not suppress `ALLOW_ADHOC_SUBQUERY` — the test will silently
pass without raising `SupersetSecurityException` even when the flag is False.
</div>
</div>
<small><i>Code Review Run #2ce454</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]