codeant-ai-for-open-source[bot] commented on code in PR #45130:
URL: https://github.com/apache/superset/pull/45130#discussion_r4226683678
##########
superset/commands/dashboard/restore.py:
##########
@@ -44,6 +101,81 @@ class
RestoreDashboardCommand(BaseRestoreCommand[Dashboard]):
forbidden_exc = DashboardForbiddenError
restore_failed_exc = DashboardRestoreFailedError
+ def prepare_restore(self, model: Dashboard) -> None:
+ """Remove controls with missing semantic targets before making them
live.
+
+ A missing target invalidates the entire control, including its
defaults.
+ Do not confuse unavailable providers or lost datasource grants with
deletion:
+ only metadata existence matters after dashboard editorship was
validated.
+ """
+ metadata: dict[str, Any] | None =
_parse_restore_metadata(model.json_metadata)
+ if metadata is None:
+ self.warnings.append(
+ "Warning: dashboard filter cleanup was skipped because its
metadata "
+ "is malformed. Review the dashboard filters before using its
results."
+ )
+ return
+ keys: tuple[str, str] = (
+ "native_filter_configuration",
+ "chart_customization_config",
+ )
+ controls: list[dict[str, Any]] = [
+ control for key in keys for control in metadata.get(key) or []
+ ]
+ semantic_ids: dict[int, set[int | None]] = {
+ id(control): {
+ _semantic_target_id(target)
+ for target in control.get("targets") or []
+ if target.get("datasourceType") == "semantic_view"
+ }
+ for control in controls
+ }
+ requested_ids: set[int] = {
+ target_id
+ for ids in semantic_ids.values()
+ for target_id in ids
+ if target_id is not None
+ }
+ existing_ids: set[int] = (
+ set(
+ db.session.scalars(
+
select(SemanticView.id).where(SemanticView.id.in_(requested_ids))
+ )
Review Comment:
**Suggestion:** If metadata contains more distinct semantic IDs than the
backend's bind-parameter limit, this unbatched `IN` query errors and prevents
restoring an otherwise valid dashboard.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Rarely` ยท ๐ท๏ธ `Possible bug`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2b82d07bfdb84392947f3ecdab003d31&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=2b82d07bfdb84392947f3ecdab003d31&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/commands/dashboard/restore.py
**Line:** 141:143
**Comment:**
*Possible Bug: If metadata contains more distinct semantic IDs than the
backend's bind-parameter limit, this unbatched `IN` query errors and prevents
restoring an otherwise valid dashboard.
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.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45130&comment_hash=9f343efbee36695875b50e2d5d57de0ea8d7b75ef0ab8b55d1973af96dfc4b83&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45130&comment_hash=9f343efbee36695875b50e2d5d57de0ea8d7b75ef0ab8b55d1973af96dfc4b83&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]