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


##########
superset/utils/oauth2.py:
##########
@@ -145,19 +183,32 @@ def refresh_oauth2_token(
         database_id=database_id,
     ):
         # Short circuit in case another request already deleted the token
-        token = (
-            db.session.query(DatabaseUserOAuth2Tokens)
-            .filter_by(user_id=user_id, database_id=database_id)
-            .one_or_none()
-        )
+        query = token_session.query(DatabaseUserOAuth2Tokens)
+        if force:
+            query = query.populate_existing()
+        token = query.filter_by(user_id=user_id, 
database_id=database_id).one_or_none()
         if token is None:
             return None
 
-        if token.access_token and datetime.now() < 
token.access_token_expiration:
+        # Another request may have refreshed the token while this caller waited
+        # for the distributed lock. Reuse the winner rather than exchanging a
+        # rotating/single-use refresh token again.
+        if (
+            force
+            and rejected_access_token is not None
+            and token.access_token != rejected_access_token
+        ):
+            return token.access_token
+
+        if (
+            not force
+            and token.access_token
+            and datetime.now() < token.access_token_expiration
+        ):
             return token.access_token
 
         if not token.refresh_token:
-            db.session.delete(token)
+            token_session.delete(token)
             return None
 

Review Comment:
   Fixed in 035cdd35c4. Forced refreshes use an isolated session, so the 
no-refresh-token path now commits the deletion before closing that session. I 
also added `test_force_refresh_commits_deletion_without_refresh_token` to cover 
the durable deletion and prevent regression.



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