Skip to content

fix(dataset): improve dataset, report, and expression validation - #42929

Merged
rusackas merged 6 commits into
masterfrom
fix/dataset-command-validation
Aug 13, 2026
Merged

rusackas merged 6 commits into
masterfrom
fix/dataset-command-validation

Conversation

@rusackas

@rusackas rusackas commented Aug 9, 2026

Copy link
Copy Markdown
Member

SUMMARY

Improves validation in the dataset-update and report/alert command paths and in stored/rendered SQL expression handling.

  • Repointing a physical dataset at a different table (or converting virtual→physical) now runs the same data-access check the create path enforces; editorship alone is not treated as data access.
  • fetch_values_predicate is routed through the same parser-based validator as stored column and metric expressions, at save time and again when it is embedded at query time.
  • Alert queries are validated when saved and when run: single-statement only, read-only unless the database allows DML, and authorized for the saving/executing user; templated SQL defers the static checks to execution time.
  • Rendered Jinja column/metric expressions are re-validated before being embedded, since save-time validation only sees the pre-render skeleton.
  • When row-level-security predicates apply to a virtual dataset but cannot be injected, the query is aborted instead of running unfiltered, and an unresolved RLS state scopes the cache key to the current user.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable (backend behavior).

TESTING INSTRUCTIONS

pytest tests/unit_tests/commands/dataset/ tests/unit_tests/commands/report/ tests/unit_tests/connectors/sqla/models_test.py tests/unit_tests/models/test_virtual_dataset_format.py

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API

@dosubot dosubot Bot added authentication:row-level-security Related to Row Level Security change:backend Requires changing the backend data:dataset Related to dataset configurations labels Aug 9, 2026
@codecov

codecov Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 52.08333% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.62%. Comparing base (885f001) to head (4ca609c).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
superset/commands/dataset/update.py 58.69% 17 Missing and 2 partials ⚠️
superset/models/helpers.py 46.66% 15 Missing and 1 partial ⚠️
superset/commands/report/base.py 42.30% 13 Missing and 2 partials ⚠️
superset/commands/report/alert.py 56.25% 5 Missing and 2 partials ⚠️
superset/connectors/sqla/models.py 30.00% 6 Missing and 1 partial ⚠️
superset/commands/report/exceptions.py 66.66% 3 Missing ⚠️
superset/commands/report/create.py 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #42929      +/-   ##
==========================================
- Coverage   66.75%   66.62%   -0.13%     
==========================================
  Files        2862     2863       +1     
  Lines      161749   162237     +488     
  Branches    37313    37400      +87     
==========================================
+ Hits       107969   108087     +118     
- Misses      51724    52082     +358     
- Partials     2056     2068      +12     
Flag Coverage Δ
hive 38.29% <15.27%> (-0.14%) ⬇️
mysql 57.86% <52.08%> (-0.20%) ⬇️
postgres 57.89% <52.08%> (-0.21%) ⬇️
presto 40.25% <15.27%> (-0.15%) ⬇️
python 59.28% <52.08%> (-0.22%) ⬇️
sqlite 57.52% <50.69%> (-0.20%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread superset/commands/report/alert.py Resolved
@bito-code-review

Copy link
Copy Markdown
Contributor

The security concern is valid. The current implementation of security_manager.raise_for_access with sql=rendered_sql may rely on default behaviors that are too permissive for raw SQL queries, potentially allowing access to tables not explicitly granted via dataset permissions. To resolve this, you should ensure that the authorization check strictly validates the tables referenced in the rendered SQL against the user's authorized datasets, rather than relying on broad database-level permissions.

To implement this, you can update the authorization logic in superset/commands/report/alert.py to extract the tables from the rendered SQL and verify each one against the user's permissions, similar to how SQL Lab enforces strict scoping.

superset/commands/report/alert.py

# Run table-level authorization as the executing user against
                # the rendered SQL.
                try:
                    # Use a stricter validator that parses the SQL and checks
                    # each referenced table against authorized datasets.
                    security_manager.raise_for_access(
                        database=self._report_schedule.database,
                        sql=rendered_sql,
                        strict_dataset_matching=True,
                    )
                except SupersetSecurityException as ex:
                    raise AlertQueryError(
                        message=_("Alert query failed the authorization check")
                    ) from ex

Comment thread superset/commands/report/alert.py Resolved
Comment thread superset/commands/report/alert.py Resolved

@bito-code-review bito-code-review Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #2ce454

Actionable Suggestions - 3
  • superset/models/helpers.py - 1
  • superset/commands/report/exceptions.py - 1
    • Missing test coverage for exceptions · Line 43-73
  • tests/unit_tests/connectors/sqla/models_test.py - 1
Additional Suggestions - 2
  • superset/commands/dataset/update.py - 1
    • Missing SQL revalidation test · Line 135-195
      The `_validate_sql_access` method correctly re-runs SQL security validation when the database binding changes, but no test exercises this path for virtual datasets. A test for `{"database_id": N, "sql": "SELECT ..."}` on a virtual dataset would close this gap and satisfy [6262].
  • superset/commands/report/create.py - 1
    • Missing test for SQL validation path · Line 132-133
      The new SQL validation branch at lines 132–133 has no test coverage in `tests/unit_tests/commands/report/create_test.py`. The existing alert tests (`test_validate_alert_missing_database_key`, `test_validate_alert_nonexistent_database`) stub out `_populate_recipients` via `_stub_validate_deps` but never reach `validate_alert_query` because they omit a `sql` key. A test exercising the SQL-validation path is needed to prevent regression.
Review Details
  • Files reviewed - 14 · Commit Range: 0b60db8..23d9bf8
    • superset/commands/dataset/update.py
    • superset/commands/report/alert.py
    • superset/commands/report/base.py
    • superset/commands/report/create.py
    • superset/commands/report/exceptions.py
    • superset/commands/report/update.py
    • superset/connectors/sqla/models.py
    • superset/models/helpers.py
    • superset/utils/rls.py
    • tests/unit_tests/commands/dataset/update_test.py
    • tests/unit_tests/commands/report/base_test.py
    • tests/unit_tests/commands/report/update_test.py
    • tests/unit_tests/connectors/sqla/models_test.py
    • tests/unit_tests/models/test_virtual_dataset_format.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/models/helpers.py Resolved
Comment thread superset/commands/report/exceptions.py Resolved
@rusackas rusackas added the merge-if-green If approved and tests are green, please go ahead and merge it for me label Aug 9, 2026
@bito-code-review

bito-code-review Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #0f4ad2

Actionable Suggestions - 0
Review Details
  • Files reviewed - 6 · Commit Range: 0b60db8..ff9c362
    • superset/commands/report/alert.py
    • superset/commands/report/base.py
    • tests/integration_tests/reports/alert_tests.py
    • tests/integration_tests/sqla_models_tests.py
    • tests/unit_tests/commands/report/alert_test.py
    • tests/unit_tests/commands/report/base_test.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@sha174n sha174n left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the validation changes across the dataset-update, report/alert, and expression paths. The approach is consistent: each new check routes through the same parser-based validators the sibling paths already use, and runs both at save time and again at the point of use on the fully rendered SQL.

Confirmed: fetch_values_predicate uses the identical validator as stored column and metric expressions; rendered Jinja expressions are re-checked after templating and before being embedded, guarded so the check only runs when the template actually changed the string; the virtual-dataset RLS path aborts the query when row-level predicates apply but cannot be added, and only proceeds when it has positively confirmed none apply; alert queries enforce single-statement plus read-only-unless-DML plus dataset-scoped table checks at both save and execution, with templated SQL correctly deferring the static checks to execution.

Two non-blocking notes: (1) validate_rendered_expression fails closed on any unparseable rendered result, whereas the existing query-time helper falls back to the raw expression for dialect-specific syntax sqlglot cannot model. Since it only runs on templated expressions the exposure is limited, but it is worth confirming the stricter behavior is intended there so legitimate templated dialect-specific expressions are not rejected at query time. (2) This touches the same _validate_dataset_source region as #42936, so a rebase or merge-order decision will be needed. LGTM.

@rusackas
rusackas force-pushed the fix/dataset-command-validation branch from ff9c362 to a510862 Compare August 11, 2026 23:25
@rusackas

Copy link
Copy Markdown
Member Author

@sha174n thanks for the read-through. Rebased over #42936 and dropped the duplicate database-access check it added in _validate_dataset_source - the existing _validate_sql_access/physical-repoint checks already covered repointing, so the two were double-calling raise_for_access and breaking #42936's own tests.

On the fail-closed question: yes, intentional. validate_rendered_expression only runs on Jinja output rendered at request time, so failing closed there is the safer default. The fallback in the stored-expression check exists for legacy dialect-specific syntax already sitting in the DB, which doesn't apply to freshly rendered SQL.

Comment thread superset/connectors/sqla/models.py Resolved
Comment thread superset/models/helpers.py Resolved
Comment thread superset/utils/rls.py Resolved
Comment thread superset/commands/dataset/update.py Resolved
Comment thread superset/commands/report/base.py Resolved
@bito-code-review

bito-code-review Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #2b5726

Actionable Suggestions - 0
Additional Suggestions - 3
  • superset/commands/dataset/update.py - 1
    • CWE-288: Validator uses stale database object · Line 371-371
      `_validate_fetch_values_predicate` re-resolves `database` from `self._properties` after `_validate_dataset_source` runs, so the new database connection (set at line 185) is never visible — the validator always falls back to `self._model.database`, using the old database even when `database_id` was changed by the caller. Pass the already-resolved `db` object from `_validate_dataset_source` instead. ([CWE-288](https://cwe.mitre.org/data/definitions/288.html))
  • superset/commands/report/update.py - 1
    • CWE-N: Missing test coverage for effective-value SQL revalidation · Line 155-163
      The new block on lines 158-163 re-validates the alert SQL using the stored value as a fallback for whichever half (sql or database) is absent from the payload. This new effective-value logic is not exercised by any existing test — `validate_alert_query` is fully stubbed and `effective_database`/`effective_sql` are never referenced in update_test.py. Adaptive rule [11730] requires unit tests covering success paths, error scenarios, and validation failures for new tools/features.
  • superset/models/helpers.py - 1
    • Missing test coverage for new function · Line 332-388
      The new `validate_rendered_expression` function lacks direct unit tests. While its logic mirrors `validate_stored_expression` (which is well-tested), the regex-based SELECT-stripping and sanitization path on the rendered value are not exercised. Add tests analogous to `test_validate_stored_expression_rejects_multi_statement` etc. in `tests/unit_tests/connectors/sqla/models_test.py`.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • tests/integration_tests/reports/alert_tests.py - 3
Review Details
  • Files reviewed - 17 · Commit Range: 04a37db..a510862
    • superset/commands/dataset/update.py
    • superset/commands/report/alert.py
    • superset/commands/report/base.py
    • superset/commands/report/create.py
    • superset/commands/report/exceptions.py
    • superset/commands/report/update.py
    • superset/connectors/sqla/models.py
    • superset/models/helpers.py
    • superset/utils/rls.py
    • tests/integration_tests/reports/alert_tests.py
    • tests/integration_tests/sqla_models_tests.py
    • tests/unit_tests/commands/dataset/update_test.py
    • tests/unit_tests/commands/report/alert_test.py
    • tests/unit_tests/commands/report/base_test.py
    • tests/unit_tests/commands/report/update_test.py
    • tests/unit_tests/connectors/sqla/models_test.py
    • tests/unit_tests/models/test_virtual_dataset_format.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

rusackas and others added 5 commits August 11, 2026 20:19
…uth; strengthen alert query validation

Require exactly one alert statement and use strict dataset matching for alert authorization.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Split _validate_dataset_source into focused helpers to satisfy ruff's
C901 complexity check, and stop re-running raise_for_access when a
database repoint already covers the same (db, table) check -- both the
new physical-repoint check and the SQL-access re-check on database_changed
were firing redundant/duplicate calls against the same target.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…st RLS cache key

- validate_rendered_expression now converts every failure mode (parse,
  set operation, disallowed sub-query, sanitization) to
  QueryObjectValidationError, matching validate_stored_expression_at_query_time,
  instead of letting SupersetSecurityException escape uncaught from its
  call sites in connectors/sqla/models.py and models/helpers.py.
- The unresolved-RLS-predicates cache-key fallback now keys guest users
  by a hash of their token's RLS rules/resources instead of
  get_user_id(), which returns None for every guest token and was
  collapsing distinct guest RLS contexts onto the same cache entry.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@rusackas
rusackas force-pushed the fix/dataset-command-validation branch from 5b34f2e to 4c1e7d2 Compare August 12, 2026 03:28

@bito-code-review bito-code-review Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #5a1d2b

Actionable Suggestions - 2
Additional Suggestions - 2
  • superset/models/helpers.py - 1
    • Docstring-implementation mismatch · Line 332-386
      `validate_rendered_expression` documents (line 346) that it may rewrite the expression with RLS predicates, but the implementation performs only validation checks (parse, set-operation, subquery, sanitization). No `apply_rls` call exists in the function body. This mismatch could cause maintainers to assume RLS protection is in place when it is not.
  • superset/commands/report/alert.py - 1
    • Typo in log message · Line 272-272
      Minor typo: 'reveal to much information' should be 'reveal too much information'. While minor, clear messaging helps security-focused warning logs.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/commands/report/update.py - 1
Review Details
  • Files reviewed - 15 · Commit Range: 2c5b655..4c1e7d2
    • superset/commands/dataset/update.py
    • superset/commands/report/alert.py
    • superset/commands/report/base.py
    • superset/commands/report/create.py
    • superset/commands/report/exceptions.py
    • superset/commands/report/update.py
    • superset/connectors/sqla/models.py
    • superset/models/helpers.py
    • tests/integration_tests/reports/alert_tests.py
    • tests/unit_tests/commands/dataset/update_test.py
    • tests/unit_tests/commands/report/alert_test.py
    • tests/unit_tests/commands/report/base_test.py
    • tests/unit_tests/commands/report/update_test.py
    • tests/unit_tests/connectors/sqla/models_test.py
    • tests/unit_tests/models/test_virtual_dataset_format.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/models/helpers.py Resolved
@bito-code-review

bito-code-review Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #573a61

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 4c1e7d2..4ca609c
    • tests/unit_tests/connectors/sqla/models_test.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@rusackas
rusackas merged commit 0915a39 into master Aug 13, 2026
65 of 68 checks passed
@rusackas
rusackas deleted the fix/dataset-command-validation branch August 13, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

authentication:row-level-security Related to Row Level Security change:backend Requires changing the backend data:dataset Related to dataset configurations merge-if-green If approved and tests are green, please go ahead and merge it for me preset-io size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants