codeant-ai-for-open-source[bot] commented on code in PR #45451:
URL: https://github.com/apache/superset/pull/45451#discussion_r4324131984


##########
superset/utils/filters.py:
##########
@@ -176,3 +177,105 @@ def guest_embedded_dashboard_filter() -> 
Optional[ColumnElement[bool]]:
         # dashboards, never a plain internal id.
         conditions.append(and_(Dashboard.id.in_(int_ids), 
Dashboard.embedded.any()))
     return or_(*conditions) if conditions else false()
+
+
+def apply_extra_access_exclusions(
+    query: "Query",
+    asset_kind: str,
+    id_column: "ColumnElement[Any]",
+) -> "Query":
+    """Withhold the asset IDs an ``EXTRA_ACCESS_QUERY_EXCLUSIONS`` hook names.
+
+    ``EXTRA_ACCESS_QUERY_FILTERS`` can only widen a result set -- its 
conditions
+    are OR'd with the role paths -- so a deployment with its own notion of a
+    withheld asset cannot express that through it. This is the matching AND 
NOT.
+
+    Returns ``query`` unchanged when no hook is configured or there is no
+    authenticated user, so the default build is unaffected.
+    """
+
+    clause = extra_access_exclusion_clause(asset_kind, id_column)
+    return query if clause is None else query.filter(clause)
+
+
+def extra_access_exclusion_clause(
+    asset_kind: str,
+    id_column: "ColumnElement[Any]",
+) -> Optional["ColumnElement[bool]"]:
+    """The ``NOT EXISTS`` clause for an exclusion hook, or None when inactive.
+
+    Deliberately ``NOT EXISTS`` rather than ``NOT IN``: a hook subquery that
+    yields a single NULL id makes ``NOT IN`` evaluate to NULL for every row,
+    which would silently empty the entire list -- for admins too. ``NOT 
EXISTS``
+    simply does not match a NULL, so a malformed hook withholds nothing instead
+    of everything.
+    """
+    hook, _reason = _extra_access_exclusion_entry(asset_kind)
+    if not hook:
+        return None
+
+    from superset.utils.core import get_user_id
+
+    user_id = get_user_id()
+    if not user_id:
+        return None
+
+    excluded = hook(user_id)
+    excluded_id = list(excluded.c)[0]

Review Comment:
   **Suggestion:** Hooks are typed to return an ORM `Query`, which has no `.c` 
attribute; returning that advertised type raises `AttributeError` before 
filtering or validating the asset.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Often` ยท ๐Ÿท๏ธ `Api mismatch`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c5a47cc510e04d168dd7d37a0a03cd52&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c5a47cc510e04d168dd7d37a0a03cd52&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/utils/filters.py
   **Line:** 223:224
   **Comment:**
        *Api Mismatch: Hooks are typed to return an ORM `Query`, which has no 
`.c` attribute; returning that advertised type raises `AttributeError` before 
filtering or validating the asset.
   
   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%2F45451&comment_hash=e4512d623e612b893e9e813ce6ccd52ee706133bb1ca8b5a89b21285639fb41b&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45451&comment_hash=e4512d623e612b893e9e813ce6ccd52ee706133bb1ca8b5a89b21285639fb41b&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]

Reply via email to