codeant-ai-for-open-source[bot] commented on code in PR #41780:
URL: https://github.com/apache/superset/pull/41780#discussion_r3680935424
##########
superset/translations/utils.py:
##########
@@ -24,9 +25,43 @@
# 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. A locale with no pack file
+# is cached as None so repeated requests don't re-stat the filesystem or
+# re-log the same warning.
+ALL_LANGUAGE_PACK_VERSIONS: dict[str, Optional[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.
+ """
+ if locale in ALL_LANGUAGE_PACK_VERSIONS:
+ return ALL_LANGUAGE_PACK_VERSIONS[locale]
+ try:
+ with open(get_language_pack_filename(locale), "rb") as f:
+ version = hashlib.sha256(f.read()).hexdigest()[:12]
+ except OSError:
+ logger.warning("No language pack file to version for locale %s",
locale)
+ version = None
+ ALL_LANGUAGE_PACK_VERSIONS[locale] = version
+ return version
Review Comment:
**Suggestion:** The version is cached indefinitely for the lifetime of each
worker, while the language-pack contents are also cached independently. After a
catalog is changed or replaced in a long-running worker, new HTML continues to
reference the old immutable URL and that URL can continue serving the stale
cached pack; a previously missing catalog also remains unavailable after it is
added. Invalidate both caches when catalogs are updated, or derive the version
from a deployment-aware/reloadable source rather than storing it permanently in
process-global state. [cache]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Long-running workers can serve outdated language packs.
- ❌ Newly added catalogs remain unavailable until restart.
- ⚠️ Immutable browser caches pin stale translation assets.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=5719d4a36be54f15888239f0d8863cab&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=5719d4a36be54f15888239f0d8863cab&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:** 53:62
**Comment:**
*Cache: The version is cached indefinitely for the lifetime of each
worker, while the language-pack contents are also cached independently. After a
catalog is changed or replaced in a long-running worker, new HTML continues to
reference the old immutable URL and that URL can continue serving the stale
cached pack; a previously missing catalog also remains unavailable after it is
added. Invalidate both caches when catalogs are updated, or derive the version
from a deployment-aware/reloadable source rather than storing it permanently in
process-global state.
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=3526bf85b9939fa0b8f1ea5aff8077e9ceec92a0b64829ab29b925b16f230be2&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41780&comment_hash=3526bf85b9939fa0b8f1ea5aff8077e9ceec92a0b64829ab29b925b16f230be2&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]