codeant-ai-for-open-source[bot] commented on code in PR #38489:
URL: https://github.com/apache/superset/pull/38489#discussion_r2899863529
##########
superset/security/manager.py:
##########
@@ -44,7 +44,7 @@
PermissionViewModelView,
ViewMenuModelView,
)
-from flask_babel import lazy_gettext as _
+from flask_babel import gettext as _
Review Comment:
**Suggestion:** Importing `gettext` as `_` means all uses of `_()` in this
module (many of which are at class definition/import time) will be translated
eagerly in the default locale instead of lazily per-request, breaking i18n
because strings like filter names will no longer respect the current user's
locale; use `lazy_gettext` for `_` instead so existing call sites remain lazily
translated while still allowing the new error message to be localized. [logic
error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ User list filter label `username` not localized per locale.
- ⚠️ Any class-level `_()` strings ignore current user locale.
- ⚠️ Inconsistent i18n: some filters localized, others stuck default.
```
</details>
```suggestion
from flask_babel import lazy_gettext as _
```
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Start Superset with the PR code so that `superset/security/manager.py` is
imported and
`_` is bound to eager gettext via `from flask_babel import gettext as _` at
line 47.
2. During import of `SupersetSecurityManager` (same file), class attributes
like
`ExcludeUsersFilter.name = _("username")` are evaluated once at import time,
storing a
plain `str` in the default server locale rather than a lazy object.
3. Access any user-listing API or view that uses
`SupersetUserApi.base_filters =
[["username", ExcludeUsersFilter, lambda: []]]` (defined in
`superset/security/manager.py`), so the UI renders the filter label from
`ExcludeUsersFilter.name`.
4. Change the active locale for a different request (e.g., configure a
different UI
language for another user or browser session) and hit the same user-listing
endpoint
again; observe that the filter label text remains in the original
import-time language
because it was translated eagerly, whereas other filters defined in modules
using
`lazy_gettext as _` (e.g. `superset/charts/filters.py`) correctly follow the
per-request
locale.
```
</details>
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/security/manager.py
**Line:** 47:47
**Comment:**
*Logic Error: Importing `gettext` as `_` means all uses of `_()` in
this module (many of which are at class definition/import time) will be
translated eagerly in the default locale instead of lazily per-request,
breaking i18n because strings like filter names will no longer respect the
current user's locale; use `lazy_gettext` for `_` instead so existing call
sites remain lazily translated while still allowing the new error message to be
localized.
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.
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38489&comment_hash=36d4f83666d4422fe67a3685e7b2ed7f3cf8dc112c8d1631c673da7333a18256&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38489&comment_hash=36d4f83666d4422fe67a3685e7b2ed7f3cf8dc112c8d1631c673da7333a18256&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]