aminghadersohi commented on code in PR #44695:
URL: https://github.com/apache/superset/pull/44695#discussion_r4113534869


##########
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:
   Fixed in 2f9e93110f. `np.datetime64` now goes through `pd.Timestamp` 
(`.item()` returns an int at ns precision), NaT becomes null, and 
`timedelta`/`np.timedelta64`/`pd.Timedelta` become `H:MM:SS` strings. Added 
`test_to_json_value_numpy_dates_and_durations`.



##########
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:
   No change. Queries use `Database.get_effective_user`, which returns the 
logged-in user (`get_username()`) whenever there is one and falls back to the 
URL username only without a request user. `impersonate_user` then looks that 
user up and uses their email. Validation always runs in a request, so 
`g.user.email` is the same principal queries would use.



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