dosubot[bot] commented on issue #31975:
URL: https://github.com/apache/superset/issues/31975#issuecomment-2610411397
<!-- Answer -->
To resolve cache retrieval issues in Superset 4.1.1 when using
`current_username()` and `url_param()` in SQL datasets with the
`GLOBAL_ASYNC_QUERIES` flag, ensure these functions are correctly included in
the cache key calculation. The `ExtraCache` class in
`superset/jinja_context.py` is responsible for this.
1. **Ensure `add_to_cache_keys` is True**: When using `current_username()`
or `url_param()`, set `add_to_cache_keys` to `True` to include their results in
the cache key.
```python
def current_username(self, add_to_cache_keys: bool = True) ->
Optional[str]:
if username := get_username():
if add_to_cache_keys:
self.cache_key_wrapper(username)
return username
return None
def url_param(
self,
param: str,
default: Optional[str] = None,
add_to_cache_keys: bool = True,
escape_result: bool = True,
) -> Optional[str]:
# ... existing logic ...
if add_to_cache_keys:
self.cache_key_wrapper(result)
return result
```
2. **Use `cache_key_wrapper`**: This method appends values to the
`extra_cache_keys` list, crucial for cache key calculation.
By following these steps, you can help ensure that cache keys are correctly
calculated, which should resolve the cache retrieval issues
<sup>[[1]](https://github.com/apache/superset/blob/master/superset/jinja_context.py)</sup>.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
---
<sup>Help Dosu learn! Give it feedback: [Great
Response](https://app.dosu.dev/response-feedback/b2b2a482-872b-4a35-90b5-2444ebe3bd43?feedback_type=great_response)
| [Irrelevant
Answer](https://app.dosu.dev/response-feedback/b2b2a482-872b-4a35-90b5-2444ebe3bd43?feedback_type=irrelevant_answer)
| [Incorrect
Sources](https://app.dosu.dev/response-feedback/b2b2a482-872b-4a35-90b5-2444ebe3bd43?feedback_type=incorrect_sources)
| [Too
Verbose](https://app.dosu.dev/response-feedback/b2b2a482-872b-4a35-90b5-2444ebe3bd43?feedback_type=too_verbose)
|
[Hallucination](https://app.dosu.dev/response-feedback/b2b2a482-872b-4a35-90b5-2444ebe3bd43?feedback_type=hallucination)
|
[Other](https://app.dosu.dev/response-feedback/b2b2a482-872b-4a35-90b5-2444ebe3bd43?feedback_type=other)</sup>
--
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]