codeant-ai-for-open-source[bot] commented on code in PR #38272:
URL: https://github.com/apache/superset/pull/38272#discussion_r2878279632
##########
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")
+
+ if native_filter_id is None or filter_type is None:
+ warning_msg = (
+ f"Skipping malformed native filter missing required "
+ f"fields: {native_filter}"
+ )
+ warnings.append(warning_msg)
+ logger.warning(warning_msg)
+ continue
+
params = {
**params,
**self._generate_native_filter(
- filter["nativeFilterId"],
- filter["filterType"],
- filter["columnName"],
- filter["filterValues"],
+ native_filter_id,
+ filter_type,
+ native_filter.get("columnName", ""),
+ native_filter.get("filterValues", []),
),
Review Comment:
**Suggestion:** When `nativeFilters` contains an entry where `filterValues`
is present but explicitly set to `None`, `get_native_filters_params` passes
`None` into `_generate_native_filter`, which for filter types like
`filter_time`, `filter_timegrain`, `filter_timecolumn`, or `filter_range` will
attempt to index `values[0]` and raise a `TypeError`. Coercing `None` to an
empty list at the call site ensures `_generate_native_filter` always receives a
list, avoiding runtime failures for such malformed but realistic inputs. [type
error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Dashboard report execution fails for malformed native filter configs.
- ❌ No screenshot/CSV/PDF generated via `AsyncExecuteReportScheduleCommand`.
- ⚠️ Affects ALERT_REPORT_TABS dashboards with saved native filters.
```
</details>
```suggestion
params = {
**params,
**self._generate_native_filter(
native_filter_id,
filter_type,
native_filter.get("columnName", ""),
native_filter.get("filterValues") or [],
),
}
```
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Create a `ReportSchedule` row in the database (table `report_schedule`
defined at
`superset/reports/models.py:121-178`) with `dashboard_id` set and the JSON
column `extra`
containing a `dashboard` key whose value follows `ReportScheduleExtra`
(`superset/reports/types.py:22-23`), e.g.:
`{"dashboard": {"nativeFilters": [{"nativeFilterId": "NATIVE_FILTER-1",
"filterType":
"filter_time", "columnName": "ds", "filterValues": null}]}}`.
2. Ensure the `ALERT_REPORT_TABS` feature flag is enabled so that
dashboard-tab URLs are
used; this causes `BaseReportState.get_dashboard_urls` in
`superset/commands/report/execute.py:258-271` to execute the branch at lines
266-271 that
calls `self._report_schedule.get_native_filters_params()`.
3. Trigger execution of the report schedule via the async command entry point
`AsyncExecuteReportScheduleCommand.run` in
`superset/commands/report/execute.py:1056-1091`
(e.g., by letting the Celery task run for that `report_schedule.id`); this
constructs a
`ReportScheduleStateMachine` and enters `ReportNotTriggeredErrorState.next`
(`execute.py:813-865`), which ultimately calls `self.send()` and
`_get_screenshots()`
(`execute.py:354-432`), which in turn calls `get_dashboard_urls()`
(`execute.py:386-400`).
4. During `get_dashboard_urls()`, the call to
`self._report_schedule.get_native_filters_params()` invokes
`ReportSchedule.get_native_filters_params` at
`superset/reports/models.py:193-232`. For
the malformed native filter, `native_filter.get("filterValues", [])` at line
226 returns
Python `None` (because the key exists but the value is JSON null), so
`_generate_native_filter` is called at lines 220-227 with `values=None`.
Inside
`_generate_native_filter` (`models.py:234-324`), any of the time-based or
range filter
branches (e.g. `filter_time` at 241-247, `filter_timegrain` at 251-261,
`filter_timecolumn` at 266-273, or `filter_range` at 295-304) attempt to
evaluate
`values[0]` or `len(values)`, raising `TypeError: 'NoneType' object is not
subscriptable`
and causing the report execution to error instead of completing.
```
</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:** 220:227
**Comment:**
*Type Error: When `nativeFilters` contains an entry where
`filterValues` is present but explicitly set to `None`,
`get_native_filters_params` passes `None` into `_generate_native_filter`, which
for filter types like `filter_time`, `filter_timegrain`, `filter_timecolumn`,
or `filter_range` will attempt to index `values[0]` and raise a `TypeError`.
Coercing `None` to an empty list at the call site ensures
`_generate_native_filter` always receives a list, avoiding runtime failures for
such malformed but realistic inputs.
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=2a2afda09250b8e7522149f165b600cec648894baf3503ec1332aeca114a13e0&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38272&comment_hash=2a2afda09250b8e7522149f165b600cec648894baf3503ec1332aeca114a13e0&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]