FrancescoCastaldi opened a new pull request, #45895:
URL: https://github.com/apache/superset/pull/45895

   ### SUMMARY
   Fixes #45877.
   
   Chart-data results for semantic views (`datasource_type: "semantic_view"`) 
were cached under the same key across all users, even when 
`CACHE_QUERY_BY_USER` was enabled.
   
   #### Root Cause
   In `QueryObject.cache_key`, per-user cache partitioning attempts to read 
`self.datasource.database`:
   ```python
   try:
       add_impersonation_cache_key_if_needed(self.datasource.database, 
cache_dict)
   except AttributeError:
       pass
   ```
   A `SemanticView` object does not have a `.database` attribute, so the 
`AttributeError` is silently caught and bypassed, omitting user isolation.
   
   #### Solution
   This PR encapsulates user cache partitioning cleanly and exclusively inside 
`SemanticView.get_extra_cache_keys()`:
   1. When `is_feature_enabled("CACHE_QUERY_BY_USER")` is true, queries 
`current_host_execution_context()`.
   2. Appends `("semantic-user", exec_context.identity_digest)` when the caller 
is not a guest (`not exec_context.is_guest`) and `identity_digest` is present.
   3. Preserves shared caching across embedded guest users (`is_guest=True`) as 
intended by the guest token security model.
   4. Leaves cache keys unpartitioned when the feature flag is disabled, 
maintaining full backward compatibility.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A (Backend caching behavior)
   
   ### TESTING INSTRUCTIONS
   Run unit tests:
   ```bash
   pytest tests/unit_tests/semantic_layers/models_test.py -k 
test_semantic_view_cache_query_by_user
   ```
   
   ### ADDITIONAL INFORMATION
   - [x] Has associated issue: Fixes #45877
   - [x] Required feature flags: `CACHE_QUERY_BY_USER`
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in SIP-59)
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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]

  • [PR] fix(se... via GitHub

Reply via email to