fix(report): raise warning when filter type not recognized#38676
fix(report): raise warning when filter type not recognized#38676sadpandajoe merged 7 commits intomasterfrom
Conversation
…andrusoare/fix/key-error-for-reports
|
Bito Automatic Review Skipped - Branch Excluded |
|
🎪 Showtime deployed environment on GHA for 482499a • Environment: http://54.188.43.165:8080 (admin/admin) |
…andrusoare/fix/handle-filter-for-reports
Sequence DiagramThis 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
Generated by CodeAnt AI |
| "extraFormData": {"time_range": values[0]}, | ||
| "filterState": {"value": values[0]}, |
There was a problem hiding this comment.
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.| "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 |
There was a problem hiding this comment.
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.| "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 |
There was a problem hiding this comment.
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.| "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.| if min_val and max_val | ||
| else f"x ≥ {min_val}" | ||
| if min_val | ||
| else f"x ≤ {max_val}" | ||
| if max_val |
There was a problem hiding this comment.
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.| 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.
Code Review Agent Run #f5a175Actionable Suggestions - 0Additional Suggestions - 2
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
(cherry picked from commit 37c4a36)
User description
SUMMARY
_generate_native_filter()encounters an unrecognized filter typeChanges
_generate_native_filter()to return a tuple(filter_config, warning)instead of justfilter_configget_native_filters_params()to collect warnings from_generate_native_filter()BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION
CodeAnt-AI Description
Skip unsupported report filters and show a warning instead of failing silently
What Changed
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:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
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:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
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.