codeant-ai-for-open-source[bot] commented on code in PR #43623:
URL: https://github.com/apache/superset/pull/43623#discussion_r3881826945
##########
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:
**Suggestion:** In forced-refresh mode `token_session` is an isolated
SQLAlchemy session, but this deletion path never commits it. The `finally`
block closes the session, rolling back the deletion, so a rejected access token
with no refresh token remains stored and every subsequent query repeats the
failed refresh-and-redirect flow. Commit the deletion in the forced session or
explicitly remove the token through the durable session. [cache]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Rejected tokens without refresh tokens remain persisted.
- ⚠️ Subsequent SQL requests repeat failed OAuth handling.
- ⚠️ Users repeatedly encounter interactive authorization fallback.
```
</details>
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=57918bacc9194cfd8be2a80cbb02620e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=57918bacc9194cfd8be2a80cbb02620e&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/oauth2.py
**Line:** 210:213
**Comment:**
*Cache: In forced-refresh mode `token_session` is an isolated
SQLAlchemy session, but this deletion path never commits it. The `finally`
block closes the session, rolling back the deletion, so a rejected access token
with no refresh token remains stored and every subsequent query repeats the
failed refresh-and-redirect flow. Commit the deletion in the forced session or
explicitly remove the token through the durable session.
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%2F43623&comment_hash=652c5de3a9c3f18ebedb3abd74b13c14a1424e16e76cd02f67fd9763cbf146d0&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43623&comment_hash=652c5de3a9c3f18ebedb3abd74b13c14a1424e16e76cd02f67fd9763cbf146d0&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]