fix(i18n): wrap table access error message with gettext for translation#38489
fix(i18n): wrap table access error message with gettext for translation#38489Harshit-Tiwary wants to merge 2 commits intoapache:masterfrom
Conversation
Code Review Agent Run #38b2eaActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
superset/security/manager.py
Outdated
| ViewMenuModelView, | ||
| ) | ||
| from flask_babel import lazy_gettext as _ | ||
| from flask_babel import gettext as _ |
There was a problem hiding this 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]
Severity Level: Major ⚠️
- ⚠️ 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.| from flask_babel import gettext as _ | |
| from flask_babel import lazy_gettext as _ |
Steps of Reproduction ✅
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.Prompt for AI Agent 🤖
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.
Code Review Agent Run #4c5a87Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
User description
SUMMARY
Wrap the SQLLab table access error message with gettext
_()so thatit becomes translatable via Superset's internationalization (i18n) system.
Previously the message was returned as a raw string and therefore could
not be translated.
This change ensures the error message can be localized properly.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable.
TESTING INSTRUCTIONS
_()and can be translated.ADDITIONAL INFORMATION
This improves i18n support for SQLLab error messages.
CodeAnt-AI Description
Make SQLLab table-access error translatable and use double-quoted table names
What Changed
Impact
✅ Localized SQLLab permission errors✅ Consistent table-name quoting in error messages✅ Translatable denied-table messages💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.