Skip to content

fix(report): raise warning when filter type not recognized#38676

Merged
sadpandajoe merged 7 commits intomasterfrom
alexandrusoare/fix/handle-filter-for-reports
Mar 24, 2026
Merged

fix(report): raise warning when filter type not recognized#38676
sadpandajoe merged 7 commits intomasterfrom
alexandrusoare/fix/handle-filter-for-reports

Conversation

@alexandrusoare
Copy link
Copy Markdown
Contributor

@alexandrusoare alexandrusoare commented Mar 16, 2026

User description

SUMMARY

Changes

  • Modified _generate_native_filter() to return a tuple (filter_config, warning) instead of just filter_config
  • When an unknown filter type is encountered, returns empty dict with a warning message
  • Updated get_native_filters_params() to collect warnings from _generate_native_filter()
  • Added tests for unknown filter type handling

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

image

TESTING INSTRUCTIONS

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

Skip unsupported report filters and show a warning instead of failing silently

What Changed

  • Report filters with an unrecognized type are now skipped, while a warning is added to the report output
  • Valid filters still load normally even when one filter in the same report is unsupported
  • Existing handling for malformed or missing filter fields remains unchanged

Impact

✅ Fewer report failures from unsupported filters
✅ Clearer report warnings
✅ More reliable scheduled reports

💡 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.

@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Mar 16, 2026

Bito Automatic Review Skipped - Branch Excluded

Bito didn't auto-review because the source or target branch is excluded from automatic reviews.
No action is needed if you didn't intend for the agent to review it. Otherwise, to manually trigger a review, type /review in a comment and save.
You can change the branch exclusion settings here, or contact your Bito workspace admin at evan@preset.io.

@alexandrusoare alexandrusoare marked this pull request as ready for review March 16, 2026 13:14
@dosubot dosubot Bot added alert-reports Namespace | Anything related to the Alert & Reports feature change:backend Requires changing the backend labels Mar 16, 2026
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.

LGTM!

@alexandrusoare alexandrusoare added hold:testing! On hold for testing 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR labels Mar 17, 2026
@github-actions github-actions Bot added 🎪 482499a 🚦 building 🎪 482499a 📅 2026-03-17T11-18 Environment 482499a created at 2026-03-17T11-18 🎪 482499a 🤡 alexandrusoare Environment 482499a requested by alexandrusoare 🎪 ⌛ 48h Environment expires after 48 hours (default) and removed 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR labels Mar 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for 482499a

@github-actions github-actions Bot added 🎪 482499a 🚦 deploying 🎪 482499a 🚦 running Environment 482499a status: running 🎪 482499a 🌐 54.188.43.165:8080 Environment 482499a URL: http://54.188.43.165:8080 (click to visit) and removed 🎪 482499a 🚦 building 🎪 482499a 🚦 running Environment 482499a status: running labels Mar 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🎪 Showtime deployed environment on GHA for 482499a

Environment: http://54.188.43.165:8080 (admin/admin)
Lifetime: 48h auto-cleanup
Updates: New commits create fresh environments automatically

@github-actions github-actions Bot removed 🎪 482499a 🚦 running Environment 482499a status: running 🎪 482499a 🤡 alexandrusoare Environment 482499a requested by alexandrusoare 🎪 482499a 🌐 54.188.43.165:8080 Environment 482499a URL: http://54.188.43.165:8080 (click to visit) 🎪 482499a 📅 2026-03-17T11-18 Environment 482499a created at 2026-03-17T11-18 labels Mar 19, 2026
@sadpandajoe sadpandajoe removed the hold:testing! On hold for testing label Mar 20, 2026
Base automatically changed from alexandrusoare/fix/key-error-for-reports to master March 24, 2026 13:43
…andrusoare/fix/handle-filter-for-reports
@codeant-ai-for-open-source codeant-ai-for-open-source Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Mar 24, 2026
@codeant-ai-for-open-source
Copy link
Copy Markdown
Contributor

Sequence Diagram

This PR changes native filter generation to return both filter config and an optional warning. When a filter type is unrecognized, the filter is skipped and a warning is propagated so it can be shown in the report execution log.

sequenceDiagram
    participant ReportJob
    participant ReportSchedule
    participant FilterBuilder
    participant ExecutionLog

    ReportJob->>ReportSchedule: Build native filter params
    loop For each native filter
        ReportSchedule->>FilterBuilder: Generate filter from filter type
        alt Filter type recognized
            FilterBuilder-->>ReportSchedule: Return filter config
            ReportSchedule->>ReportSchedule: Merge config into params
        else Filter type unrecognized
            FilterBuilder-->>ReportSchedule: Return empty config and warning
            ReportSchedule->>ReportSchedule: Skip filter and collect warning
        end
    end
    ReportSchedule-->>ReportJob: Return params and warnings
    ReportJob->>ExecutionLog: Add warnings to report execution log
Loading

Generated by CodeAnt AI

Comment on lines +254 to +255
"extraFormData": {"time_range": values[0]},
"filterState": {"value": values[0]},
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: Accessing the first element of the filter values without checking for emptiness can raise IndexError for time filters when filterValues is missing or empty. Use a guarded first-value expression so malformed but recoverable payloads are skipped gracefully instead of crashing report execution. [possible bug]

Severity Level: Critical 🚨
- ❌ Dashboard report run fails on empty time filter.
- ⚠️ Execution log records ERROR instead of success.
Suggested change
"extraFormData": {"time_range": values[0]},
"filterState": {"value": values[0]},
"extraFormData": {
"time_range": values[0] if values else None
},
"filterState": {"value": values[0] if values else None},
Steps of Reproduction ✅
1. Create/update a report schedule with `extra.dashboard.nativeFilters` containing a valid
`nativeFilterId`, `filterType: "filter_time"`, and `filterValues: []`; validation in
`superset/commands/report/base.py:153-190` requires list type but does not require
non-empty values.

2. Enable tabs execution path (`ALERT_REPORT_TABS`) and run the report;
`BaseReportState.get_dashboard_urls()` calls
`self._report_schedule.get_native_filters_params()` at
`superset/commands/report/execute.py:268-271`.

3. In `ReportSchedule.get_native_filters_params()` (`superset/reports/models.py:220-225`),
empty values are passed as `native_filter.get("filterValues") or []`, so
`_generate_native_filter(..., values=[])` is called.

4. `_generate_native_filter()` time branch accesses `values[0]` at
`superset/reports/models.py:254-255`, raising `IndexError: list index out of range`.

5. The exception bubbles during screenshot URL generation
(`superset/commands/report/execute.py:390`) and report execution is marked error in
`next()` catch block (`superset/commands/report/execute.py:831-858`).
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/reports/models.py
**Line:** 254:255
**Comment:**
	*Possible Bug: Accessing the first element of the filter values without checking for emptiness can raise `IndexError` for time filters when `filterValues` is missing or empty. Use a guarded first-value expression so malformed but recoverable payloads are skipped gracefully instead of crashing report execution.

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

native_filter_id or "": {
"id": native_filter_id or "",
"extraFormData": {
"time_grain_sqla": values[0], # grain
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: The time-grain branch indexes values[0] unconditionally, which raises IndexError if a report stores this filter with no selected value. Guard the access and emit None when no value is present to keep report generation resilient. [possible bug]

Severity Level: Critical 🚨
- ❌ Time-grain native filter can crash report execution.
- ⚠️ Report recipients miss scheduled dashboard delivery.
Suggested change
"time_grain_sqla": values[0], # grain
"time_grain_sqla": values[0] if values else None, # grain
Steps of Reproduction ✅
1. Save a report native filter with `filterType: "filter_timegrain"` and `filterValues:
[]`; API-side native filter validation (`superset/commands/report/base.py:153-190`)
accepts empty lists.

2. During report execution with tabs enabled, `get_dashboard_urls()` invokes
`get_native_filters_params()` (`superset/commands/report/execute.py:268-271`).

3. `get_native_filters_params()` forwards `[]` into `_generate_native_filter()` via
`native_filter.get("filterValues") or []` (`superset/reports/models.py:224-225`).

4. In `_generate_native_filter()` time-grain branch, `values[0]` at
`superset/reports/models.py:267` raises `IndexError`.

5. The error propagates before screenshot capture and the run transitions to ERROR
(`superset/commands/report/execute.py:390`, `831-858`).
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/reports/models.py
**Line:** 267:267
**Comment:**
	*Possible Bug: The time-grain branch indexes `values[0]` unconditionally, which raises `IndexError` if a report stores this filter with no selected value. Guard the access and emit `None` when no value is present to keep report generation resilient.

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

{
native_filter_id or "": {
"extraFormData": {
"granularity_sqla": values[0] # column_name
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: The time-column branch also assumes at least one value and will throw IndexError for empty filterValues, causing the full report URL generation to fail. Add an emptiness check before reading the first item. [possible bug]

Severity Level: Critical 🚨
- ❌ Time-column filter can abort screenshot generation flow.
- ⚠️ Scheduled dashboard report ends in ERROR state.
Suggested change
"granularity_sqla": values[0] # column_name
"granularity_sqla": values[0] if values else None # column_name
Steps of Reproduction ✅
1. Persist a report filter payload using `filterType: "filter_timecolumn"` with
`filterValues: []`; this passes `_validate_native_filters` list checks in
`superset/commands/report/base.py:180-190`.

2. Execute dashboard report with tabs enabled so `BaseReportState.get_dashboard_urls()`
enters native filter URL generation (`superset/commands/report/execute.py:266-271`).

3. `ReportSchedule.get_native_filters_params()` passes empty values to
`_generate_native_filter()` (`superset/reports/models.py:220-225`).

4. `_generate_native_filter()` time-column branch reads `values[0]` at
`superset/reports/models.py:284`, triggering `IndexError` on empty list.

5. Exception interrupts dashboard URL construction
(`superset/commands/report/execute.py:390`) and report execution is logged as failure
(`superset/commands/report/execute.py:831-858`).
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/reports/models.py
**Line:** 284:284
**Comment:**
	*Possible Bug: The time-column branch also assumes at least one value and will throw `IndexError` for empty `filterValues`, causing the full report URL generation to fail. Add an emptiness check before reading the first item.

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

Comment on lines +337 to +341
if min_val and max_val
else f"x ≥ {min_val}"
if min_val
else f"x ≤ {max_val}"
if max_val
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: Using truthiness to build the range label treats valid numeric bounds like 0 as absent, producing incorrect labels. Compare against None explicitly so zero is handled as a real boundary value. [logic error]

Severity Level: Major ⚠️
- ⚠️ Range filter label incorrect for zero boundary values.
- ⚠️ Dashboard filter state text can mislead report viewers.
Suggested change
if min_val and max_val
else f"x ≥ {min_val}"
if min_val
else f"x ≤ {max_val}"
if max_val
if min_val is not None and max_val is not None
else f"x ≥ {min_val}"
if min_val is not None
else f"x ≤ {max_val}"
if max_val is not None
Steps of Reproduction ✅
1. In the report UI flow, range inputs accept numeric zero (`InputNumber`) and store it in
`filterValues` (`superset-frontend/src/features/alerts/AlertReportModal.tsx:227-252`,
payload mapping at `898-913`).

2. Run report generation so backend builds native filter params; range branch computes
`min_val`/`max_val` with `None` checks (`superset/reports/models.py:320-321`).

3. Label construction uses truthiness checks (`superset/reports/models.py:336-342`), so
`min_val=0` is treated as absent.

4. Generated `filterState.label` becomes incorrect (e.g., not showing lower bound `0`)
while filter operators are still built correctly from `is not None` checks
(`superset/reports/models.py:324-327`).

5. Incorrect label is serialized into the `native_filters` URL payload returned by
`get_native_filters_params()` (`superset/reports/models.py:230-232`) and used in dashboard
tab URLs (`superset/commands/report/execute.py:55`).
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/reports/models.py
**Line:** 337:341
**Comment:**
	*Logic Error: Using truthiness to build the range label treats valid numeric bounds like `0` as absent, producing incorrect labels. Compare against `None` explicitly so zero is handled as a real boundary value.

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 24, 2026

Code Review Agent Run #f5a175

Actionable Suggestions - 0
Additional Suggestions - 2
  • superset/reports/models.py - 2
    • Potential IndexError or wrong variable in filter_timecolumn · Line 279-292
      filter_timecolumn accesses values[0] for granularity_sqla without checking if values is non-empty, and the comment suggests using column_name instead. This could cause IndexError or incorrect behavior.
    • Incorrect comment in filter_time · Line 248-250
      The comment mentions 'select filters' but this is the filter_time case, which uses time_range. This appears to be a copy-paste error.
Review Details
  • Files reviewed - 2 · Commit Range: 06c1f43..26a1e0b
    • superset/reports/models.py
    • tests/unit_tests/reports/model_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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@sadpandajoe sadpandajoe merged commit 37c4a36 into master Mar 24, 2026
65 checks passed
@sadpandajoe sadpandajoe deleted the alexandrusoare/fix/handle-filter-for-reports branch March 24, 2026 23:06
michael-s-molina pushed a commit that referenced this pull request Mar 26, 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 size/L size:L This PR changes 100-499 lines, ignoring generated files 🎪 ⌛ 48h Environment expires after 48 hours (default)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants