codeant-ai-for-open-source[bot] commented on code in PR #43781:
URL: https://github.com/apache/superset/pull/43781#discussion_r3930320251
##########
superset/dashboards/filters.py:
##########
@@ -167,19 +168,57 @@ def _apply_viewers(self, query: Query) -> Query:
filters.append(Dashboard.id.in_(viewer_query))
# (C) No-viewer fallback: dashboards with no viewers โ dataset-based
access
+ # Note: for ordinary users a dashboard with no charts is never yielded
+ # here (every access predicate is NULL-false after the outer joins)
+ # even though the object gate allows opening it โ a deliberate,
+ # pre-existing asymmetry. For ``all_datasource_access`` holders the
+ # spliced literal True below yields such rows, matching the gate.
dashboard_has_viewers = Dashboard.viewers.any()
no_viewer_query = (
db.session.query(Dashboard.id)
.join(Dashboard.slices, isouter=True)
- .join(SqlaTable, Slice.datasource_id == SqlaTable.id)
- .join(Database, SqlaTable.database_id == Database.id)
+ # Type-aware datasource joins: the SqlaTable join is constrained
+ # to table-backed charts (an unconstrained id join can bind a
+ # semantic-view chart to an unrelated table sharing its numeric
+ # id) and kept outer so charts on other datasource types survive
+ # into the access filter โ their access matches through the perm
+ # columns denormalized onto Slice by ``set_related_perm``.
+ .join(
+ SqlaTable,
+ and_(
+ Slice.datasource_id == SqlaTable.id,
+ Slice.datasource_type == DatasourceType.TABLE,
+ ),
+ isouter=True,
+ )
+ .join(Database, SqlaTable.database_id == Database.id, isouter=True)
+ # A datasource_access grant on a semantic LAYER covers its views,
+ # as SemanticView.raise_for_access enforces on the data path
+ # (sc-119501) โ surface those dashboards here too, through the
+ # same type-guarded outer-join shape as the SqlaTable join.
+ .join(
+ SemanticView,
+ and_(
+ Slice.datasource_id == SemanticView.id,
+ Slice.datasource_type == DatasourceType.SEMANTIC_VIEW,
+ ),
+ isouter=True,
+ )
+ .join(
+ SemanticLayer,
+ SemanticView.semantic_layer_uuid == SemanticLayer.uuid,
+ isouter=True,
+ )
.filter(
and_(
Dashboard.published.is_(True),
~dashboard_has_viewers,
get_dataset_access_filters(
Slice,
security_manager.can_access_all_datasources(),
+ SemanticLayer.perm.in_(
+
security_manager.user_view_menu_names("datasource_access")
+ ),
),
Review Comment:
**Suggestion:** The filter still checks the stale `Slice.perm` for view
grants, so renamed or regenerated semantic-view permissions can hide dashboards
that the live object gate allows. [stale reference]
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=bf286487bdad49848c80aef31b02e561&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=bf286487bdad49848c80aef31b02e561&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/dashboards/filters.py
**Line:** 216:222
**Comment:**
*Stale Reference: The filter still checks the stale `Slice.perm` for
view grants, so renamed or regenerated semantic-view permissions can hide
dashboards that the live object gate allows.
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%2F43781&comment_hash=d881d007ca1a9ca7b747a363b52340bd025a0543e29e542fb06284871f7cf302&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43781&comment_hash=d881d007ca1a9ca7b747a363b52340bd025a0543e29e542fb06284871f7cf302&reaction=dislike'>๐</a>
##########
superset/models/slice.py:
##########
@@ -230,6 +231,59 @@ def _display_datasource(self) -> SqlaTable | SemanticView
| None:
return self.semantic_view
return self.table
+ @property
+ def resolved_datasource(self) -> Datasource | None:
+ """The chart's datasource, resolved across datasource types.
+
+ ``Slice.datasource`` is pinned to table-backed datasources (the
+ ``table`` relationship joins on ``datasource_type == 'table'``), so
+ charts on other datasource types โ semantic views in particular โ
+ resolve to ``None`` there. Authorization call sites must use this
+ resolver instead, so those charts participate in access checks
+ rather than silently vanishing from them.
+
+ Returns ``None`` when the datasource row does not exist, the type is
+ unknown, or the resolved model does not participate in access
+ control (no ``perm``, e.g. ``SavedQuery``); callers must treat
+ ``None`` as inaccessible, never as absent. Non-table lookups issue a
+ database query on every access โ deduplicate before calling this in
+ a loop.
+ """
+ if not self.datasource_id:
+ return None
+ if self.datasource_type == utils.DatasourceType.TABLE:
+ return self.table
+ if self.datasource_type == utils.DatasourceType.SEMANTIC_VIEW:
+ # Resolved through the type-guarded ``semantic_view`` relationship
+ # rather than a DAO query: identity-map cached, and its join
+ # predicate already enforces the type constraint. ``None`` when
+ # the row is gone, matching the DAO fallback's semantics.
+ return self.semantic_view
+ # pylint: disable=import-outside-toplevel
+ # Deferred to avoid a circular import: superset.daos.datasource
+ # imports connectors and sql_lab models at module top.
+ from superset.daos.datasource import DatasourceDAO
+ from superset.daos.exceptions import (
+ DatasourceNotFound,
+ DatasourceTypeNotSupportedError,
+ DatasourceValueIsIncorrect,
+ )
+
+ try:
+ resolved = DatasourceDAO.get_datasource(
+ self.datasource_type, self.datasource_id
+ )
Review Comment:
**Suggestion:** Each distinct non-table, non-semantic datasource triggers a
separate DAO query, so authorization becomes an N+1 database operation for
dashboards with many such charts. [performance]
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Rarely`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=1ba1735b7d324fe887d50facfd52369c&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=1ba1735b7d324fe887d50facfd52369c&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/models/slice.py
**Line:** 273:275
**Comment:**
*Performance: Each distinct non-table, non-semantic datasource triggers
a separate DAO query, so authorization becomes an N+1 database operation for
dashboards with many such charts.
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%2F43781&comment_hash=596547c2ef3d1cba847978960d7429228316c897eb76d43178b5b28c3c73b893&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43781&comment_hash=596547c2ef3d1cba847978960d7429228316c897eb76d43178b5b28c3c73b893&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]