codeant-ai-for-open-source[bot] commented on code in PR #41780:
URL: https://github.com/apache/superset/pull/41780#discussion_r3526393817
##########
superset/translations/utils.py:
##########
@@ -37,11 +70,7 @@ def get_language_pack(locale: str) -> Optional[dict[str,
Any]]:
"""
pack = ALL_LANGUAGE_PACKS.get(locale)
if not pack:
- filename = DIR + f"/{locale}/LC_MESSAGES/messages.json"
- if not locale or locale == "en":
- # Forcing a dummy, quasy-empty language pack for English since the
file
- # in the en directory is contains data with empty mappings
- filename = DIR + "/empty_language_pack.json"
+ filename = get_language_pack_filename(locale)
Review Comment:
**Suggestion:** Add an explicit type annotation for `filename` since this
newly added variable has a concrete string type. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The new local variable `filename` is introduced without a type hint even
though the return type of `get_language_pack_filename()` is explicitly `str`.
This is a real omission under the type-hint rule for relevant variables.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d4e10d672908436f9fff70ea3dc0526d&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=d4e10d672908436f9fff70ea3dc0526d&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/translations/utils.py
**Line:** 73:73
**Comment:**
*Custom Rule: Add an explicit type annotation for `filename` since this
newly added variable has a concrete string type.
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%2F41780&comment_hash=1e8b067f411ff54c39660bdae4bdaa330d4db064d90f5db023bb07ab090a7ee0&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41780&comment_hash=1e8b067f411ff54c39660bdae4bdaa330d4db064d90f5db023bb07ab090a7ee0&reaction=dislike'>👎</a>
##########
superset/translations/utils.py:
##########
@@ -24,9 +25,41 @@
# Global caching for JSON language packs
ALL_LANGUAGE_PACKS: dict[str, dict[str, Any]] = {"en": {}}
+# Global caching for language pack content hashes, used to build
+# content-addressed (cache-busting) asset URLs
+ALL_LANGUAGE_PACK_VERSIONS: dict[str, str] = {}
+
DIR = os.path.dirname(os.path.abspath(__file__))
+def get_language_pack_filename(locale: str) -> str:
+ """Resolve the on-disk JSON pack for a locale (empty pack for English)"""
+ if not locale or locale == "en":
+ # Forcing a dummy, quasi-empty language pack for English since the file
+ # in the en directory contains data with empty mappings
+ return DIR + "/empty_language_pack.json"
+ return DIR + f"/{locale}/LC_MESSAGES/messages.json"
+
+
+def get_language_pack_version(locale: str) -> Optional[str]:
+ """Get/cache a short content hash of the language pack file
+
+ The hash is embedded in the pack's asset URL so browsers can cache it
+ as immutable and pick up a fresh copy whenever translations change.
+ Returns None when the pack file cannot be read.
+ """
+ version = ALL_LANGUAGE_PACK_VERSIONS.get(locale)
Review Comment:
**Suggestion:** Add an explicit type annotation for `version` to satisfy the
type-hint rule for relevant newly introduced variables. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The new local variable `version` is introduced without a type hint, and its
type is statically knowable as `Optional[str]` from the `.get()` call. This
matches the rule requiring type hints for relevant newly added variables.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f92c37bab1eb4099a7776ed460965684&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=f92c37bab1eb4099a7776ed460965684&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/translations/utils.py
**Line:** 51:51
**Comment:**
*Custom Rule: Add an explicit type annotation for `version` to satisfy
the type-hint rule for relevant newly introduced variables.
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%2F41780&comment_hash=23edc67b68b6274ea676de2f8f3a70f999f37ff6deecda641f686e2fda9cb31d&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41780&comment_hash=23edc67b68b6274ea676de2f8f3a70f999f37ff6deecda641f686e2fda9cb31d&reaction=dislike'>👎</a>
##########
superset/views/core.py:
##########
@@ -917,6 +918,48 @@ def language_pack(self, lang: str) -> FlaskResponse:
"Language pack doesn't exist on the server", status=404
)
+ @expose("/language_pack/<lang>/<version>/script.js")
+ def language_pack_script(self, lang: str, version: str) -> FlaskResponse:
+ """Serve the language pack as a content-addressed classic script.
+
+ spa.html loads this BEFORE the entry bundle so translations are
+ configured synchronously (no race with code-split chunks), while the
+ versioned URL lets browsers cache the pack as immutable and pick up a
+ fresh copy whenever translations change.
+
+ Deliberately unauthenticated: translation catalogs are static, public
+ content shipped in the Superset repo, contain no user or tenant data,
+ and must load for anonymous principals (login page, embedded).
+ """
+ # Only allow expected language formats like "en", "pt_BR", etc.
+ if not re.match(r"^[a-z]{2,3}(_[A-Z]{2})?$", lang):
+ abort(400, "Invalid language code")
+ if not re.match(r"^[0-9a-f]{12}$", version):
+ abort(400, "Invalid language pack version")
+
Review Comment:
**Suggestion:** Add an explicit type annotation for this local variable to
satisfy the type-hint requirement. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The new local variable is introduced without a type annotation, and its
value is used as a version string/None sentinel. This matches the rule
requiring type hints for relevant annotatable variables in modified Python code.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a0220e1330e248bbb4e7f3ddb215e9a6&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=a0220e1330e248bbb4e7f3ddb215e9a6&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/views/core.py
**Line:** 939:939
**Comment:**
*Custom Rule: Add an explicit type annotation for this local variable
to satisfy the type-hint requirement.
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%2F41780&comment_hash=d144036b1fb617b88a80f83cbcde660641117a73d8cd9160590b060098205bcc&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41780&comment_hash=d144036b1fb617b88a80f83cbcde660641117a73d8cd9160590b060098205bcc&reaction=dislike'>👎</a>
##########
superset/views/core.py:
##########
@@ -917,6 +918,48 @@ def language_pack(self, lang: str) -> FlaskResponse:
"Language pack doesn't exist on the server", status=404
)
+ @expose("/language_pack/<lang>/<version>/script.js")
+ def language_pack_script(self, lang: str, version: str) -> FlaskResponse:
+ """Serve the language pack as a content-addressed classic script.
+
+ spa.html loads this BEFORE the entry bundle so translations are
+ configured synchronously (no race with code-split chunks), while the
+ versioned URL lets browsers cache the pack as immutable and pick up a
+ fresh copy whenever translations change.
+
+ Deliberately unauthenticated: translation catalogs are static, public
+ content shipped in the Superset repo, contain no user or tenant data,
+ and must load for anonymous principals (login page, embedded).
+ """
+ # Only allow expected language formats like "en", "pt_BR", etc.
+ if not re.match(r"^[a-z]{2,3}(_[A-Z]{2})?$", lang):
+ abort(400, "Invalid language code")
+ if not re.match(r"^[0-9a-f]{12}$", version):
+ abort(400, "Invalid language pack version")
+
+ current_version = get_language_pack_version(lang)
Review Comment:
**Suggestion:** Add an explicit type annotation for this local variable so
the new code fully complies with required type hints. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The added local variable is unannotated even though its inferred type can be
expressed. This is a direct omission under the Python type-hint requirement for
annotatable variables.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9b6255a4226b4acdbaa9cc255033f639&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=9b6255a4226b4acdbaa9cc255033f639&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/views/core.py
**Line:** 940:940
**Comment:**
*Custom Rule: Add an explicit type annotation for this local variable
so the new code fully complies with required type hints.
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%2F41780&comment_hash=4c6798973c304a5b57b43c9ff6c51d836f85cc3fb6d0fa87cbe3fd3fc50f522c&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41780&comment_hash=4c6798973c304a5b57b43c9ff6c51d836f85cc3fb6d0fa87cbe3fd3fc50f522c&reaction=dislike'>👎</a>
##########
superset/views/core.py:
##########
@@ -917,6 +918,48 @@ def language_pack(self, lang: str) -> FlaskResponse:
"Language pack doesn't exist on the server", status=404
)
+ @expose("/language_pack/<lang>/<version>/script.js")
+ def language_pack_script(self, lang: str, version: str) -> FlaskResponse:
+ """Serve the language pack as a content-addressed classic script.
+
+ spa.html loads this BEFORE the entry bundle so translations are
+ configured synchronously (no race with code-split chunks), while the
+ versioned URL lets browsers cache the pack as immutable and pick up a
+ fresh copy whenever translations change.
+
+ Deliberately unauthenticated: translation catalogs are static, public
+ content shipped in the Superset repo, contain no user or tenant data,
+ and must load for anonymous principals (login page, embedded).
+ """
+ # Only allow expected language formats like "en", "pt_BR", etc.
+ if not re.match(r"^[a-z]{2,3}(_[A-Z]{2})?$", lang):
+ abort(400, "Invalid language code")
+ if not re.match(r"^[0-9a-f]{12}$", version):
+ abort(400, "Invalid language pack version")
+
+ current_version = get_language_pack_version(lang)
+ pack = get_language_pack(lang)
+ if current_version is None or pack is None:
+ return json_error_response(
+ "Language pack doesn't exist on the server", status=404
+ )
+
+ response = Response(
+ f"window.__SUPERSET_LANGUAGE_PACK__ = {json.dumps(pack)};",
+ mimetype="application/javascript; charset=utf-8",
+ )
Review Comment:
**Suggestion:** Provide a type annotation for this response variable to keep
local typing explicit in new code. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The new response variable is assigned without an explicit type annotation,
despite being a clearly annotatable local object in modified Python code. This
falls under the type-hint rule.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=ddf66474b74249e9b6c566652130831a&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=ddf66474b74249e9b6c566652130831a&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/views/core.py
**Line:** 947:950
**Comment:**
*Custom Rule: Provide a type annotation for this response variable to
keep local typing explicit in new code.
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%2F41780&comment_hash=c288e40c4e66b90c5700bb6b3cc6d6de39d18cfe07cd92372a2222e3a49a4e22&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41780&comment_hash=c288e40c4e66b90c5700bb6b3cc6d6de39d18cfe07cd92372a2222e3a49a4e22&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]