codeant-ai-for-open-source[bot] commented on code in PR #38272:
URL: https://github.com/apache/superset/pull/38272#discussion_r2939949838
##########
superset/reports/models.py:
##########
@@ -187,24 +190,46 @@ def __repr__(self) -> str:
def crontab_humanized(self) -> str:
return get_description(self.crontab)
- def get_native_filters_params(self) -> str:
+ def get_native_filters_params(self) -> tuple[str, list[str]]:
+ """
+ Generate native filter params for dashboard URL.
+
+ Returns:
+ A tuple of (rison_encoded_params, list_of_warning_messages).
+ Warnings are returned so they can be surfaced to users in the
+ execution log.
+ """
params: dict[str, Any] = {}
+ warnings: list[str] = []
dashboard = self.extra.get("dashboard")
if dashboard and dashboard.get("nativeFilters"):
- for filter in dashboard.get("nativeFilters") or []: # type: ignore
+ native_filters = dashboard.get("nativeFilters") or []
+ for native_filter in native_filters: # type: ignore
+ native_filter_id = native_filter.get("nativeFilterId")
+ filter_type = native_filter.get("filterType")
Review Comment:
**Suggestion:** `nativeFilters` is consumed as a list of dicts, but the code
never validates that shape. If `extra_json` contains a non-list value (or list
elements that are not dicts), calling `.get()` on `native_filter` will raise
`AttributeError` and crash report execution. Validate the container and each
item before accessing keys, and skip malformed entries with a warning. [type
error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ reports.execute task can fail for malformed nativeFilters.
- ❌ Dashboard tab screenshot flow aborts before notification delivery.
- ⚠️ Execution logs contain unexpected-error noise, not filter warnings.
```
</details>
```suggestion
native_filters = dashboard.get("nativeFilters") or []
if not isinstance(native_filters, list):
warning_msg = (
"Skipping malformed nativeFilters payload: expected
list, "
f"got {type(native_filters).__name__}"
)
warnings.append(warning_msg)
logger.warning(warning_msg)
native_filters = []
for native_filter in native_filters:
if not isinstance(native_filter, dict):
warning_msg = (
"Skipping malformed native filter entry: expected
object, "
f"got {type(native_filter).__name__}"
)
warnings.append(warning_msg)
logger.warning(warning_msg)
continue
native_filter_id = native_filter.get("nativeFilterId")
filter_type = native_filter.get("filterType")
```
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Create or update a report schedule through `ReportScheduleRestApi.post`
(`superset/reports/api.py:358`) with `extra.dashboard.nativeFilters` set to
a non-list
(schema allows generic dict via `extra = fields.Dict` in
`superset/reports/schemas.py:232-234`).
2. Ensure the schedule is a dashboard report path with tabs enabled
(`ALERT_REPORT_TABS`),
then trigger execution via Celery task `reports.execute`
(`superset/tasks/scheduler.py:117-135`), which runs
`AsyncExecuteReportScheduleCommand`.
3. Execution reaches `BaseReportState.get_dashboard_urls`
(`superset/commands/report/execute.py:258-272`), which calls
`ReportSchedule.get_native_filters_params()`
(`superset/reports/models.py:193`).
4. In `get_native_filters_params`, loop at `superset/reports/models.py:207`
iterates
malformed entries and line `208` calls `native_filter.get(...)`; for
non-dict items this
raises `AttributeError`, which bubbles to `ReportScheduleUnexpectedError`
(`superset/commands/report/execute.py:1090-1091`) and task failure handling
(`superset/tasks/scheduler.py:36-40`).
```
</details>
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/reports/models.py
**Line:** 206:209
**Comment:**
*Type Error: `nativeFilters` is consumed as a list of dicts, but the
code never validates that shape. If `extra_json` contains a non-list value (or
list elements that are not dicts), calling `.get()` on `native_filter` will
raise `AttributeError` and crash report execution. Validate the container and
each item before accessing keys, and skip malformed entries with a warning.
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.
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38272&comment_hash=24808fe64b2f80d988995763a1c0c37ed2f8fe57afa41179f1e86498a0c5cba0&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38272&comment_hash=24808fe64b2f80d988995763a1c0c37ed2f8fe57afa41179f1e86498a0c5cba0&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]