codeant-ai-for-open-source[bot] commented on code in PR #42597:
URL: https://github.com/apache/superset/pull/42597#discussion_r3707383041
##########
superset/common/query_object.py:
##########
@@ -440,6 +440,18 @@ def cache_key(self, **extra: Any) -> str: # noqa: C901
cache_dict: dict[str, Any] = dict(self.to_dict())
cache_dict.update(extra)
+ if "extra_cache_keys" in cache_dict:
+ # Order carries no meaning here (an unordered set of opaque
+ # Jinja url_param()-derived values), but hash_from_dict only
+ # sorts dict keys, not list values, so an unsorted list makes
+ # the cache key depend on Python's per-process hash-randomized
+ # set iteration order (see SqlaTable.get_extra_cache_keys).
+ # Normalize once here so every producer of extra_cache_keys is
+ # safe by construction.
+ cache_dict["extra_cache_keys"] = sorted(
+ cache_dict["extra_cache_keys"], key=str
+ )
Review Comment:
**Suggestion:** The `key=str` sort is not a complete canonicalization for
the declared `Hashable` value domain. Distinct values such as integer `1` and
string `"1"` have the same sort key, so Python's stable sort preserves
whichever order the producer supplied; because
`SqlaTable.get_extra_cache_keys()` derives its list from a set, that order can
still differ between processes and produce different cache keys. Use a
type-aware deterministic ordering (or normalize each value with an unambiguous
type/value representation) so values with equal string representations are
ordered consistently. [cache]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Mixed user-ID and URL-parameter queries can miss async chart-data caches.
- ⚠️ Affected requests may return “Error loading data from cache.”
- ⚠️ Cache duplication can occur across worker and web processes.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f8ef9641a8a848e2aed17a8a3e6c26eb&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=f8ef9641a8a848e2aed17a8a3e6c26eb&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/common/query_object.py
**Line:** 451:453
**Comment:**
*Cache: The `key=str` sort is not a complete canonicalization for the
declared `Hashable` value domain. Distinct values such as integer `1` and
string `"1"` have the same sort key, so Python's stable sort preserves
whichever order the producer supplied; because
`SqlaTable.get_extra_cache_keys()` derives its list from a set, that order can
still differ between processes and produce different cache keys. Use a
type-aware deterministic ordering (or normalize each value with an unambiguous
type/value representation) so values with equal string representations are
ordered consistently.
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%2F42597&comment_hash=226f2f9c973eb4aeb22d9ec881df6a3d25783e3bf21f899c9182f6e69786582b&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42597&comment_hash=226f2f9c973eb4aeb22d9ec881df6a3d25783e3bf21f899c9182f6e69786582b&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]