codeant-ai-for-open-source[bot] commented on code in PR #36856:
URL: https://github.com/apache/superset/pull/36856#discussion_r3632448306
##########
superset/db_engine_specs/snowflake.py:
##########
@@ -192,6 +243,113 @@ class SnowflakeEngineSpec(PostgresBaseEngineSpec):
),
}
+ # OAuth 2.0 support
+ supports_oauth2: bool = True
+ oauth2_exception: type[Exception] = CustomSnowflakeAuthError
+
+ @classmethod
+ def is_oauth2_enabled(cls) -> bool:
+ """
+ Return whether OAuth2 authentication is enabled.
+ """
+
+ # When alerts or reports connect to the database in the background,
+ # OAuth2 authentication fails; therefore, OAuth2 authentication is
disabled
+ # for background execution.
+ if not has_request_context():
+ return False
+
+ return (
+ cls.supports_oauth2
+ and cls.engine_name in app.config["DATABASE_OAUTH2_CLIENTS"]
+ )
Review Comment:
**Suggestion:** This direct config indexing can raise a runtime KeyError
when the OAuth client map is not defined in config, causing Snowflake auth
checks to fail unexpectedly. Use a safe lookup with a default empty mapping to
avoid breaking connection setup. [possible bug]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Snowflake OAuth checks crash if config key missing.
- ⚠️ Database connection setup fails for misconfigured deployments.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Start a Superset instance where the Flask app configuration does not
define
`DATABASE_OAUTH2_CLIENTS` (for example, a custom config predating this OAuth
feature or
one that accidentally omits the key).
2. Trigger any code path that evaluates Snowflake OAuth support, such as
calling
`SnowflakeEngineSpec.get_oauth2_config()` (defined at
`superset/db_engine_specs/snowflake.py:268-275`), which internally calls
`SnowflakeEngineSpec.is_oauth2_enabled()` at lines 250-265.
3. When `SnowflakeEngineSpec.is_oauth2_enabled()` executes at
`superset/db_engine_specs/snowflake.py:262-265`, it evaluates
`cls.supports_oauth2 and
cls.engine_name in app.config["DATABASE_OAUTH2_CLIENTS"]`.
4. Because `DATABASE_OAUTH2_CLIENTS` is missing from `app.config`, the
direct indexing at
line 264 raises a `KeyError`, causing the OAuth enablement check and any
calling
connection-setup logic to fail with an unhandled exception rather than
cleanly falling
back to non-OAuth authentication.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=7fc9bdd3eb974f3eaf8f82b23a3c65dd&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=7fc9bdd3eb974f3eaf8f82b23a3c65dd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/db_engine_specs/snowflake.py
**Line:** 262:265
**Comment:**
*Possible Bug: This direct config indexing can raise a runtime KeyError
when the OAuth client map is not defined in config, causing Snowflake auth
checks to fail unexpectedly. Use a safe lookup with a default empty mapping to
avoid breaking connection setup.
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%2F36856&comment_hash=2b90a2c20802fcb3edad49155a212ad760ae42aa65d9a58225a358700df997de&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F36856&comment_hash=2b90a2c20802fcb3edad49155a212ad760ae42aa65d9a58225a358700df997de&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]