Skip to content

fix(reports): null-guard execution against missing target - #39973

Merged
rusackas merged 2 commits into
apache:masterfrom
mikebridge:sc-106186-reports-null-guard
Jul 16, 2026
Merged

rusackas merged 2 commits into
apache:masterfrom
mikebridge:sc-106186-reports-null-guard

Conversation

@mikebridge

@mikebridge mikebridge commented May 8, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

Adds a defensive null-guard at the top of BaseReportState._get_url (superset/commands/report/execute.py). When both self._report_schedule.chart and self._report_schedule.dashboard are None, the method now raises ReportScheduleUnexpectedError with a message identifying the report and the missing target, rather than crashing on a downstream dashboard.id access in the dashboard.uuid if dashboard and dashboard.uuid else dashboard.id ternary. Previous behaviour was to raise a AttributeError: 'NoneType' object has no attribute 'id' and surface it in the UI.

This is a pre-existing latent issue. ReportSchedule.dashboard and .chart are nullable in the schema, but reaching the dual-None state was practically unreachable in master because every code path that could orphan a report blocks the deletion (e.g., DeleteChartCommand blocks delete when reports reference the chart). The guard makes the failure mode explicit and informative if any future code path (or any direct DB write) ever does land in that state.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend-only change; no UI or API surface changes.

TESTING INSTRUCTIONS

pytest tests/unit_tests/commands/report/execute_test.py -v

Expected: 48 passed (47 pre-existing + the new test_get_url_raises_unexpected_error_when_target_is_missing).

The new test constructs a ReportSchedule mock with both .chart and .dashboard returning None and asserts _get_url raises ReportScheduleUnexpectedError with a message containing the report id, name, chart_id, and dashboard_id.

ADDITIONAL INFORMATION

  • Has associated issue: sc-106186
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

@codecov

codecov Bot commented May 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.03%. Comparing base (18f1dd3) to head (643491e).

Files with missing lines Patch % Lines
superset/commands/report/execute.py 33.33% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #39973      +/-   ##
==========================================
- Coverage   65.03%   65.03%   -0.01%     
==========================================
  Files        2744     2744              
  Lines      153627   153630       +3     
  Branches    35226    35227       +1     
==========================================
+ Hits        99910    99911       +1     
- Misses      51810    51813       +3     
+ Partials     1907     1906       -1     
Flag Coverage Δ
hive 39.04% <0.00%> (-0.01%) ⬇️
mysql 57.90% <33.33%> (-0.01%) ⬇️
postgres 57.96% <33.33%> (-0.01%) ⬇️
presto 41.03% <0.00%> (-0.01%) ⬇️
python 59.34% <33.33%> (-0.01%) ⬇️
sqlite 57.56% <33.33%> (-0.01%) ⬇️
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.

@mikebridge

Copy link
Copy Markdown
Member Author

Note on the Codecov 66.67% patch coverage warning

Both Codecov gates (codecov/patch, codecov/project) pass. The warning comes from the per-flag breakdown:

  • unit flag: 100% — tests/unit_tests/commands/report/execute_test.py::test_get_url_raises_unexpected_error_when_target_is_missing covers every new line.
  • python / postgres / mysql / sqlite (integration) flags: 66.66% — integration tests can't reach the dual-None state by design.

The codepath the new guard protects (both chart and dashboard returning None from the relationship) is intentionally unreachable in production: DeleteChartCommand and DeleteDashboardCommand already block deletion of a target that has reports referencing it. The guard is defense-in-depth — it activates only if a future code path or a direct SQL write ever produces an orphaned report. Constructing that state cleanly from an integration test would require bypassing the very validation the guard protects against.

Project coverage actually rose by +0.06% with this change.

@mikebridge
mikebridge marked this pull request as ready for review May 8, 2026 19:07
@dosubot dosubot Bot added alert-reports Namespace | Anything related to the Alert & Reports feature change:backend Requires changing the backend labels May 8, 2026
@mikebridge

Copy link
Copy Markdown
Member Author

Note: playwright-tests (chromium, /app/prefix) flake

This same job ran twice on the same SHA (74040fcbb4):

Run Result
actions/runs/25571381551 ✅ SUCCESS
actions/runs/25574299079 ❌ FAILURE

Same code, opposite outcomes — canonical flake signature. The failing tests are also in completely unrelated files (dashboard-list.spec.ts bulk delete, dashboard/export.spec.ts, sqllab/sqllab.spec.ts queries) — this PR only touches superset/commands/report/execute.py. All errors are TimeoutError: page.waitForResponse: Timeout 15000ms exceeded.

The non-prefix variant playwright-tests (chromium) passed both times; the experimental playwright variants all passed too.

I don't have rerun rights on this repo (fork PR). If a committer reviewing this could kick off a rerun, the flake should clear and the PR will be fully green.

@mikebridge

Copy link
Copy Markdown
Member Author

@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #418495

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: f2eb8bb..74040fc
    • superset/commands/report/execute.py
    • tests/unit_tests/commands/report/execute_test.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a defensive null-guard in BaseReportState._get_url to raise a meaningful ReportScheduleUnexpectedError when both chart and dashboard relationships are None, instead of crashing with an AttributeError on dashboard.id. Also simplifies the dashboard id/slug selection.

Changes:

  • Raise ReportScheduleUnexpectedError early in _get_url when neither chart nor dashboard is resolvable.
  • Simplify dashboard_id_or_slug selection to dashboard.uuid or dashboard.id.
  • Add a unit test covering the new guard.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
superset/commands/report/execute.py Adds null-guard at top of _get_url and simplifies dashboard id/slug fallback.
tests/unit_tests/commands/report/execute_test.py Adds test asserting the guard raises with a message containing report id, name, chart_id, dashboard_id.

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

bito-code-review Bot commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #bbce59

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 693ddf0..91dada3
    • superset/commands/report/execute.py
    • tests/unit_tests/commands/report/execute_test.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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

@mikebridge
mikebridge force-pushed the sc-106186-reports-null-guard branch from 91dada3 to 964a591 Compare May 18, 2026 17:02
@bito-code-review

bito-code-review Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #97d1f0

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 90a6800..964a591
    • superset/commands/report/execute.py
    • tests/unit_tests/commands/report/execute_test.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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

@mikebridge
mikebridge force-pushed the sc-106186-reports-null-guard branch from 964a591 to 0dcc66d Compare May 25, 2026 17:45
@bito-code-review

bito-code-review Bot commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #528a35

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 849ede8..0dcc66d
    • superset/commands/report/execute.py
    • tests/unit_tests/commands/report/execute_test.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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

@mikebridge
mikebridge force-pushed the sc-106186-reports-null-guard branch from 0dcc66d to 1c3f86f Compare June 30, 2026 15:56
@netlify

netlify Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 48d7eb0
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a571bc7747b6e000806e075
😎 Deploy Preview https://deploy-preview-39973--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@bito-code-review

bito-code-review Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #b6c46f

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 9ba505d..1c3f86f
    • superset/commands/report/execute.py
    • tests/unit_tests/commands/report/execute_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 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bot comments worth a look, but seems like a good defensive fix. Test covers it well, LGTM

@mikebridge
mikebridge force-pushed the sc-106186-reports-null-guard branch from 1c3f86f to e534a5c Compare July 13, 2026 19:05
Comment thread superset/commands/report/execute.py Resolved
Comment thread superset/commands/report/execute.py Resolved
@mikebridge
mikebridge force-pushed the sc-106186-reports-null-guard branch 2 times, most recently from 45b338c to ac224bd Compare July 13, 2026 19:13
@mikebridge

mikebridge commented Jul 13, 2026 •

Copy link
Copy Markdown
Member Author

@rusackas The rebased PR is approved, mergeable, and all addressed review threads are resolved. The fresh required Playwright run hit one unrelated timeout in dashboard/delete-display-control.spec.ts plus four unrelated dataset/dashboard flakes; this PR only changes report URL resolution. I do not have repository admin rights to rerun failed jobs (gh run rerun 29277667917 --failed is denied). Could you please rerun the failed Playwright job?

EDIT: I will just rebase and push to trigger CI again

@mikebridge
mikebridge force-pushed the sc-106186-reports-null-guard branch from ac224bd to 41a858c Compare July 13, 2026 19:46
@mikebridge
mikebridge force-pushed the sc-106186-reports-null-guard branch from 41a858c to 7365845 Compare July 13, 2026 19:53
Comment thread superset/commands/report/execute.py Resolved
Adds a defensive null-guard at the top of
``BaseReportState._get_url`` (``superset/commands/report/execute.py``).
When both ``self._report_schedule.chart`` and
``self._report_schedule.dashboard`` are ``None``, the method now raises
``ReportScheduleUnexpectedError`` with a message identifying the report
and the missing target, rather than crashing on the downstream
``dashboard.id`` access at the (formerly) ``else`` branch of the
``dashboard.uuid if dashboard and dashboard.uuid else dashboard.id``
ternary.

This is a pre-existing latent bug — ``_report_schedule.dashboard`` was
already nullable in principle, but reaching the ``None`` state was
practically unreachable in master because every code path that orphaned
a report was blocked by ``DeleteChartCommand`` /
``DeleteDashboardCommand`` validation.

The soft-delete branch makes the bug newly reachable through admin
tooling / direct SQLAlchemy paths that bypass the validation: the
visibility filter applied to relationship loads returns ``None`` for
soft-deleted targets even though the FK still references the row. The
existing API protections still block the most common trigger path
(``DELETE /api/v1/chart/<id>`` returns 422 when reports reference the
chart), so production scheduled reports are unaffected.

Adds a unit test in ``tests/unit_tests/commands/report/execute_test.py``
that constructs a ``ReportSchedule`` mock with both relationships
returning ``None`` and asserts the new error is raised with the right
identifying details (report id, name, chart_id, dashboard_id).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@mikebridge
mikebridge force-pushed the sc-106186-reports-null-guard branch from 7365845 to 643491e Compare July 13, 2026 20:10
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Jul 13, 2026
@bito-code-review

bito-code-review Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #fac7ab

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 643491e..643491e
    • superset/commands/report/execute.py
    • tests/unit_tests/commands/report/execute_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

Comment on lines 327 to 329
dashboard_id_or_slug = (
dashboard.uuid if dashboard and dashboard.uuid else dashboard.id
dashboard.uuid if dashboard.uuid is not None else dashboard.id
)

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.

Suggestion: Provide an explicit type annotation for this newly added computed variable so its expected identifier type is statically enforced. [custom_rule]

Severity Level: Minor 🧹

Why it matters? ⭐

This newly added computed local variable is inferable as a value that can be annotated, but no type hint is provided. That matches the custom Python type-hint rule, so the violation is real.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/commands/report/execute.py
**Line:** 327:329
**Comment:**
	*Custom Rule: Provide an explicit type annotation for this newly added computed variable so its expected identifier type is statically enforced.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +2357 to +2360
get_url_path = mocker.patch(
"superset.commands.report.execute.get_url_path",
return_value="/chart",
)

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.

Suggestion: Add an explicit type annotation for this newly introduced local variable to satisfy the type-hint requirement for annotatable variables. [custom_rule]

Severity Level: Minor 🧹

Why it matters? ⭐

This is newly added Python code in a test, and the local variable get_url_path is inferable and can be annotated (for example as a mock object). Since the custom rule requires type hints on annotatable new or modified variables, this omission is a real violation.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/commands/report/execute_test.py
**Line:** 2357:2360
**Comment:**
	*Custom Rule: Add an explicit type annotation for this newly introduced local variable to satisfy the type-hint requirement for annotatable variables.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@rusackas
rusackas merged commit 635b181 into apache:master Jul 16, 2026
55 checks passed
rdg0 pushed a commit to rdg0/superset that referenced this pull request Jul 20, 2026
Co-authored-by: Mike Bridge <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Co-authored-by: Evan Rusackas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

alert-reports Namespace | Anything related to the Alert & Reports feature change:backend Requires changing the backend size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants