Skip to content

fix(reports): validate nativeFilters on report create/update and deactivate on dashboard filter deletion#38715

Merged
EnxDev merged 3 commits into
masterfrom
enxdev/fix/validate-native-filters-on-report-create-update
Mar 20, 2026
Merged

fix(reports): validate nativeFilters on report create/update and deactivate on dashboard filter deletion#38715
EnxDev merged 3 commits into
masterfrom
enxdev/fix/validate-native-filters-on-report-create-update

Conversation

@EnxDev
Copy link
Copy Markdown
Contributor

@EnxDev EnxDev commented Mar 18, 2026

User description

SUMMARY

Reports scheduled from dashboards can include native filter state (nativeFilters) in
their extra.dashboard payload. Previously, this field was never validated — any
arbitrary data was accepted at creation/update time and only crashed at execution when
the scheduler tried to read required keys from the filter objects.

Changes:

  • Added _validate_native_filters() to BaseReportScheduleCommand validating that
    each nativeFilters item has all required keys (nativeFilterId, filterType,
    columnName, filterValues), that filterValues is a list, and that
    nativeFilterId references a filter that actually exists on the dashboard
  • Moved _validate_report_extra() to BaseReportScheduleCommand so validation runs
    on both create and update (previously only ran on create)
  • Added process_native_filter_diff() to UpdateDashboardCommand — when a native
    filter is removed from a dashboard, any report referencing that filter ID is
    deactivated and each report owner receives an email notification
  • Added ReportScheduleDAO.find_by_native_filter_id() for filter ID lookups
  • Extracted shared _send_deactivated_report_email() helper to avoid duplicating the
    HTML email template between tab and filter deactivation flows

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

  1. Create a dashboard with no native filters configured
  2. POST to /api/v1/report/ with extra: {"dashboard": {"nativeFilters": [{"garbage": true}]}} → expect 422
  3. POST with a valid nativeFilterId that doesn't exist on the dashboard → expect 422
  4. POST with a valid nativeFilterId that exists on the dashboard and filterValues: [] → expect 201
  5. Same validations apply on PUT
  6. Create a report referencing a valid native filter, then remove that filter from the
    dashboard via PUT /api/v1/dashboard/:id → report is deactivated and owner receives
    email

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

CodeAnt-AI Description

Validate native dashboard filters on report create/update and deactivate reports when dashboard filters are removed

What Changed

  • Creating or updating a scheduled report now rejects invalid dashboard nativeFilters with a 422 error (garbage entries, missing required keys, non-list values, or a nativeFilterId not present on the dashboard).
  • When a native filter is removed from a dashboard, any scheduled reports that reference that filter are deactivated and each report owner receives an email notification.
  • Validation of report.extra.dashboard runs on both create and update; added tests cover invalid inputs and the deactivation/email behavior.

Impact

✅ Fewer report creation/update errors slipping to execution
✅ Clearer deactivation emails when dashboard filters are removed
✅ Fewer failing scheduled reports after dashboard changes

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@dosubot dosubot Bot added alert-reports Namespace | Anything related to the Alert & Reports feature api Related to the REST API change:backend Requires changing the backend dashboard:native-filters Related to the native filters of the Dashboard labels Mar 18, 2026
@codeant-ai-for-open-source codeant-ai-for-open-source Bot added the size:XL This PR changes 500-999 lines, ignoring generated files label Mar 18, 2026
@codeant-ai-for-open-source
Copy link
Copy Markdown
Contributor

Sequence Diagram

This PR adds native filter validation when creating or updating report schedules, preventing invalid dashboard filter payloads from being saved. It also deactivates existing reports and notifies owners when referenced dashboard native filters are removed.

sequenceDiagram
    participant User
    participant ReportAPI
    participant ReportCommand
    participant DashboardAPI
    participant ReportDAO
    participant EmailService

    User->>ReportAPI: Create or update report with nativeFilters
    ReportAPI->>ReportCommand: Validate nativeFilters against dashboard filters
    alt Invalid nativeFilters
        ReportCommand-->>ReportAPI: Validation error
        ReportAPI-->>User: Reject request with validation message
    else Valid nativeFilters
        ReportCommand-->>ReportAPI: Validation passed
        ReportAPI-->>User: Save report schedule
    end

    User->>DashboardAPI: Update dashboard and remove native filter
    DashboardAPI->>ReportDAO: Find reports using deleted filter ids
    DashboardAPI->>ReportDAO: Deactivate matched reports
    DashboardAPI->>EmailService: Send deactivation emails to report owners
Loading

Generated by CodeAnt AI

Comment thread superset/commands/dashboard/update.py
Comment thread superset/commands/dashboard/update.py
Comment thread superset/commands/report/base.py
Comment thread superset/commands/report/base.py
Comment thread superset/commands/report/base.py
Comment thread superset/commands/report/update.py
Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

Code Review Agent Run #bee052

Actionable Suggestions - 1
  • superset/commands/report/base.py - 1
Filtered by Review Rules

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

  • superset/commands/dashboard/update.py - 1
Review Details
  • Files reviewed - 6 · Commit Range: 1c3be78..1c3be78
    • superset/commands/dashboard/update.py
    • superset/commands/report/base.py
    • superset/commands/report/create.py
    • superset/commands/report/update.py
    • superset/daos/report.py
    • tests/integration_tests/reports/api_tests.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/commands/report/base.py Outdated
@github-actions github-actions Bot removed the api Related to the REST API label Mar 18, 2026
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Mar 18, 2026

Code Review Agent Run #cd4909

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 1c3be78..a44ba63
    • superset/commands/dashboard/update.py
    • superset/commands/report/base.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Copy link
Copy Markdown
Member

@msyavuz msyavuz left a comment

Choose a reason for hiding this comment

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

Looks good to me, testing should probably focus on previously valid update requests for reports

current_exec = next(schedule)

for _ in range(iterations):
for _i in range(iterations):
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.

This looks unnecessary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I renamed the loop variable to avoid Ruff flagging it as shadowed

@msyavuz msyavuz added the hold:testing! On hold for testing label Mar 18, 2026
Comment thread superset/daos/report.py
@codeant-ai-for-open-source codeant-ai-for-open-source Bot added size:XL This PR changes 500-999 lines, ignoring generated files and removed size:XL This PR changes 500-999 lines, ignoring generated files labels Mar 19, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 19, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 46131d6
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69bbd7374eb29a0008f02df6
😎 Deploy Preview https://deploy-preview-38715--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

Comment on lines +209 to +210
for f in json_metadata.get("native_filter_configuration", [])
if "id" in f
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: native_filter_configuration is allowed to be null in dashboard metadata, but iterating directly over json_metadata.get("native_filter_configuration", []) will raise TypeError when it is None. Coerce it to an empty list before iterating. [possible bug]

Severity Level: Major ⚠️
- ❌ Report create/update can fail with server exception.
- ⚠️ Native filter validation breaks on nullable dashboard metadata.
Suggested change
for f in json_metadata.get("native_filter_configuration", [])
if "id" in f
for f in (json_metadata.get("native_filter_configuration") or [])
if isinstance(f, dict) and "id" in f
Steps of Reproduction ✅
1. Store dashboard metadata with `"native_filter_configuration": null`; this is
schema-valid because `DashboardJSONMetadataSchema` sets `allow_none=True`
(`superset/dashboards/schemas.py:142`).

2. Create or update report via `/api/v1/report/` or `/api/v1/report/<id>`
(`superset/reports/api.py`), with `extra.dashboard.nativeFilters` present.

3. Validation enters `_validate_native_filters()`
(`superset/commands/report/base.py:134-224`) from create/update validate flows
(`create.py:140-141`, `update.py:133-134`).

4. Set comprehension iterates `json_metadata.get("native_filter_configuration", [])`
(`base.py:209`); when value is `None`, iteration raises `TypeError`, causing request
failure instead of clean 422 validation.
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/commands/report/base.py
**Line:** 209:210
**Comment:**
	*Possible Bug: `native_filter_configuration` is allowed to be `null` in dashboard metadata, but iterating directly over `json_metadata.get("native_filter_configuration", [])` will raise `TypeError` when it is `None`. Coerce it to an empty list before iterating.

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.
👍 | 👎

@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Mar 19, 2026

Code Review Agent Run #3e4446

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: a44ba63..46131d6
    • superset/daos/report.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@EnxDev EnxDev removed the hold:testing! On hold for testing label Mar 20, 2026
@EnxDev EnxDev merged commit e088979 into master Mar 20, 2026
75 of 78 checks passed
@EnxDev EnxDev deleted the enxdev/fix/validate-native-filters-on-report-create-update branch March 20, 2026 16:20
michael-s-molina pushed a commit that referenced this pull request Mar 20, 2026
qfcwell pushed a commit to qfcwell/superset that referenced this pull request May 12, 2026
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 dashboard:native-filters Related to the native filters of the Dashboard size/XL size:XL This PR changes 500-999 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants