bito-code-review[bot] commented on code in PR #43499:
URL: https://github.com/apache/superset/pull/43499#discussion_r4085371148


##########
superset/models/sql_lab.py:
##########
@@ -575,6 +575,66 @@ def to_dict(self) -> dict[str, Any]:
             "id": self.id,
         }
 
+    @property
+    def name(self) -> str:
+        """
+        Expose ``label`` as ``name`` so callers that treat a ``SavedQuery`` as
+        a generic datasource (e.g. chart create/update commands) can rely on
+        a uniform ``name`` attribute across all datasource types.
+
+        ``label`` is a nullable column, so fall back to an id-based name
+        rather than returning ``None`` from a property typed as ``str``.
+        """
+        return self.label or f"Saved query {self.id}"
+
+    @property
+    def schema_perm(self) -> Optional[str]:
+        """
+        Schema-level permission string, mirroring ``Query.schema_perm``.
+
+        Required so that ``SecurityManager.raise_for_access(datasource=...)``
+        and the ``Slice`` ``before_insert``/``before_update`` listener (which
+        copies ``perm``/``catalog_perm``/``schema_perm`` onto the chart) can
+        treat a ``SavedQuery`` like any other datasource instead of raising
+        ``AttributeError``.
+        """
+        return f"{self.database.database_name}.{self.schema}"

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>schema_perm format mismatch</b></div>
   <div id="fix">
   
   `SavedQuery.schema_perm` returns `"db.schema"` (no brackets), but 
`schema_access` perms are stored via `security_manager.get_schema_perm` as 
`"[db].[schema]"` (manager.py:2369-2371). `can_access_schema` (manager.py:2497) 
compares against that stored form, so schema-level grants never match a 
saved-query datasource and legitimate access is denied. Mirror 
`Query.schema_perm` by calling `get_schema_perm(...)`.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
           return security_manager.get_schema_perm(
               self.database.database_name, self.catalog, self.schema
           )
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #77baf9</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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]

Reply via email to