korbit-ai[bot] commented on code in PR #32485:
URL: https://github.com/apache/superset/pull/32485#discussion_r1977995751
##########
superset/db_engine_specs/base.py:
##########
@@ -1792,6 +1788,38 @@ def estimate_query_cost( # pylint:
disable=too-many-arguments
]
@classmethod
+ def impersonate_user(
+ cls,
+ database: Database,
+ username: str | None,
+ user_token: str | None,
+ url: URL,
+ engine_kwargs: dict[str, Any],
+ ) -> tuple[URL, dict[str, Any]]:
+ """
+ Modify URL and/or engine kwargs to impersonate a different user.
+ """
+ # Update URL using old methods until 6.0.0.
+ url = cls.get_url_for_impersonation(url, True, username, user_token)
+
+ # Update engine kwargs using old methods. Note that #30674 modified
the method
+ # signature, so we need to check if the method has the old signature.
+ connect_args = engine_kwargs.setdefault("connect_args", {})
+ args = [
+ connect_args,
+ url,
+ username,
+ user_token,
+ ]
+ if "database" in signature(cls.update_impersonation_config).parameters:
+ args.insert(0, database)
+
+ cls.update_impersonation_config(*args)
Review Comment:
### Missing parameter validation in impersonation config <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The logic to handle different method signatures doesn't verify if all
required parameters are present before making the call to
update_impersonation_config.
###### Why this matters
Without proper parameter validation, this could lead to runtime errors if
required parameters are missing or in wrong order.
###### Suggested change ∙ *Feature Preview*
Add parameter validation before calling the method:
```python
sig = signature(cls.update_impersonation_config)
required_params = [param for param in sig.parameters.values()
if param.default == param.empty]
if len(args) < len(required_params):
raise ValueError(f"Missing required parameters for
update_impersonation_config: {required_params}")
cls.update_impersonation_config(*args)
```
</details>
<sub>
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/c31a7f21-bf93-444b-ad68-2f577a4aeda1?suggestedFixEnabled=true)
💬 Chat with Korbit by mentioning @korbit-ai.
</sub>
<!--- korbi internal id:3d2f16b6-150f-4907-a541-accbfc420c37 -->
--
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]