bito-code-review[bot] commented on code in PR #33189:
URL: https://github.com/apache/superset/pull/33189#discussion_r2921224869
##########
tests/unit_tests/utils/test_core.py:
##########
@@ -1122,3 +1125,30 @@ def test_get_stacktrace():
except Exception:
stacktrace = get_stacktrace()
assert stacktrace is None
+
+
[email protected](
+ "mock_locale,expected_phrase",
+ [
+ ("en", "a day ago"),
+ ("fr", "il y a 1 jour"),
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Parametrize decorator expects tuple not string</b></div>
<div id="fix">
The first argument to `pytest.mark.parametrize` should be a tuple of
parameter names, not a string. Change `"mock_locale,expected_phrase"` to
`("mock_locale", "expected_phrase")`.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
("mock_locale", "expected_phrase"),
[
("en", "a day ago"),
("fr", "il y a 1 jour"),
````
</div>
</details>
</div>
<small><i>Code Review Run #3787dc</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset/utils/core.py:
##########
@@ -1954,3 +1956,9 @@ def get_user_agent(database: Database, source:
QuerySource | None) -> str:
return user_agent_func(database, source)
return DEFAULT_USER_AGENT
+
+
+def activate_humanize_locale() -> None:
+ if (locale := get_locale() or "en") != "en":
+ language = LOCALES_LANGUAGE_MAP.get(locale, "en_US")
+ humanize.i18n.activate(language)
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Locale object mishandling in humanize activation</b></div>
<div id="fix">
The activate_humanize_locale function appears to treat the result of
get_locale() as a string, but flask_babel's get_locale() returns a babel.Locale
object. This could lead to incorrect locale activation for humanize, resulting
in English output instead of the user's expected language. If the locale object
isn't properly accessed, the lookup in LOCALES_LANGUAGE_MAP might fail or
default incorrectly.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
def activate_humanize_locale() -> None:
if (locale := get_locale()) and locale.language != "en":
language = LOCALES_LANGUAGE_MAP.get(locale.language, "en_US")
humanize.i18n.activate(language)
````
</div>
</details>
</div>
<small><i>Code Review Run #3787dc</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]