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


##########
superset/db_engine_specs/gsheets.py:
##########
@@ -411,11 +436,13 @@ def validate_parameters(
                 )
                 return errors
 
-        # We need a subject in case domain wide delegation is set, otherwise 
the
-        # check will fail. This means that the admin will be able to add sheets
-        # that only they have access, even if later users are not able to 
access
-        # them.
-        subject = g.user.email if g.user else None
+        # Impersonate the admin only when the database impersonates users, as
+        # queries do (see ``impersonate_user``). With domain wide delegation 
this
+        # means that the admin will be able to add sheets that only they have
+        # access to; without delegation a subject makes every check fail.
+        subject = (
+            g.user.email if g.user and properties.get("impersonate_user") else 
None
+        )

Review Comment:
   **Suggestion:** Validation impersonates `g.user.email`, but queries 
impersonate the database URL's effective username, so validation may check 
access as the wrong Google principal.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `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=8ebc6ba353424e2089034a50b812e3bb&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=8ebc6ba353424e2089034a50b812e3bb&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/db_engine_specs/gsheets.py
   **Line:** 443:445
   **Comment:**
        *Api Mismatch: Validation impersonates `g.user.email`, but queries 
impersonate the database URL's effective username, so validation may check 
access as the wrong Google principal.
   
   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%2F44695&comment_hash=6e436ca6652778593343b51c5962bda2c3167e028810cb2557a844cd46d79fe0&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44695&comment_hash=6e436ca6652778593343b51c5962bda2c3167e028810cb2557a844cd46d79fe0&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/db_engine_specs/gsheets.py:
##########
@@ -64,6 +66,28 @@
 ma_plugin = MarshmallowPlugin()
 
 
+def to_json_value(value: Any) -> Any:
+    """
+    Convert a dataframe cell into a JSON value the Sheets API parses back.
+
+    Dates and timestamps become ISO strings (``USER_ENTERED`` input parses them
+    as dates), and numpy scalars become Python scalars.
+    """
+    if value is None:
+        return None
+    if isinstance(value, pd.Timestamp):
+        value = value.to_pydatetime()
+    if isinstance(value, datetime):
+        return value.isoformat(sep=" ")
+    if isinstance(value, (date, time)):
+        return value.isoformat()
+    if isinstance(value, Decimal):
+        return str(value)
+    if isinstance(value, np.generic):
+        return value.item()

Review Comment:
   **Suggestion:** `np.generic.item()` can return `datetime` or `timedelta`, 
which remains non-JSON-serializable and causes uploads to fail during the 
Sheets request.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Type error`
   
   [![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=b3c8e4c052ad417cb1cdf46ce6e32b06&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=b3c8e4c052ad417cb1cdf46ce6e32b06&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/db_engine_specs/gsheets.py
   **Line:** 86:87
   **Comment:**
        *Type Error: `np.generic.item()` can return `datetime` or `timedelta`, 
which remains non-JSON-serializable and causes uploads to fail during the 
Sheets request.
   
   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%2F44695&comment_hash=5189ddd83b6a6dd5208ea72659e0018837dfd80df6d5ad142ad6f50d861df4c2&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44695&comment_hash=5189ddd83b6a6dd5208ea72659e0018837dfd80df6d5ad142ad6f50d861df4c2&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