fix: Enforce per-user caching on legacy API endpoint#39789
fix: Enforce per-user caching on legacy API endpoint#39789Vitor-Avila merged 1 commit intomasterfrom
Conversation
Code Review Agent Run #abcfceActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
| from superset.utils.core import override_user | ||
|
|
||
|
|
||
| def _flag(name: str): |
There was a problem hiding this comment.
Suggestion: Add an explicit return type annotation to _flag so the helper has fully typed input and output. [custom_rule]
Severity Level: Minor
Why it matters? 🤔
The helper is only partially typed: name has a type annotation, but the function has no return type annotation.
This matches the suggested custom rule about fully typing new helper functions, so the violation is real.
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/utils/test_impersonation_cache_key.py
**Line:** 27:27
**Comment:**
*Custom Rule: Add an explicit return type annotation to `_flag` so the helper has fully typed input and output.
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| def side_effect(feature=None): | ||
| return feature == name |
There was a problem hiding this comment.
Suggestion: Add explicit type hints for the side_effect parameter and return value so the nested function is fully typed. [custom_rule]
Severity Level: Minor
Why it matters? 🤔
The nested side_effect function has neither a parameter type annotation nor a return type annotation.
That is a real typing omission in the new code, so the suggestion is verified.
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/utils/test_impersonation_cache_key.py
**Line:** 30:31
**Comment:**
*Custom Rule: Add explicit type hints for the `side_effect` parameter and return value so the nested function is fully typed.
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|
|
||
| def test_no_per_user_caching_yields_no_key(): | ||
| database = Database(database_name="d", sqlalchemy_uri="sqlite://") | ||
| with override_user(User(username="u")): | ||
| assert "impersonation_key" not in _run(database) |
There was a problem hiding this comment.
Suggestion: Add a short docstring to this test function describing the expected behavior being validated. [custom_rule]
Severity Level: Minor
Why it matters? 🤔
This test function has no docstring in the final file state.
If the custom rule requires docstrings for new tests, this is a real violation.
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/utils/test_impersonation_cache_key.py
**Line:** 42:46
**Comment:**
*Custom Rule: Add a short docstring to this test function describing the expected behavior being validated.
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|
|
||
|
|
||
| @patch("superset.utils.cache_keys.feature_flag_manager") | ||
| def test_cache_query_by_user_adds_username(feature_flag_mock): |
There was a problem hiding this comment.
Suggestion: Add explicit type annotations for the patched mock argument and the None return type on this new test function. [custom_rule]
Severity Level: Minor
Why it matters? 🤔
The patched test function is missing both a type annotation for feature_flag_mock and an explicit -> None return type.
This is a direct mismatch with the suggested typing rule, so the issue is present.
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/utils/test_impersonation_cache_key.py
**Line:** 50:50
**Comment:**
*Custom Rule: Add explicit type annotations for the patched mock argument and the `None` return type on this new test function.
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| def test_per_user_caching_in_extra_json_enables_key(): | ||
| database = Database( | ||
| database_name="d", | ||
| sqlalchemy_uri="sqlite://", | ||
| extra='{"per_user_caching": true}', | ||
| ) | ||
| with override_user(User(username="alice")): | ||
| assert _run(database)["impersonation_key"] == "alice" |
There was a problem hiding this comment.
Suggestion: Add a docstring to this test function so the intent of the scenario is documented consistently with the rule. [custom_rule]
Severity Level: Minor
Why it matters? 🤔
The test function does not include a docstring.
Assuming the custom rule requires docstrings for new test scenarios, this is a genuine violation.
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/utils/test_impersonation_cache_key.py
**Line:** 86:93
**Comment:**
*Custom Rule: Add a docstring to this test function so the intent of the scenario is documented consistently with the rule.
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| QUERY_OBJ: dict[str, Any] = {"row_limit": 100, "from_dttm": None, "to_dttm": None} | ||
|
|
||
|
|
||
| def _viz_for(database: Database) -> viz.BaseViz: |
There was a problem hiding this comment.
Suggestion: Add a short docstring to this helper function to describe its purpose and expected behavior. [custom_rule]
Severity Level: Minor
Why it matters? 🤔
The helper function _viz_for is newly introduced and has no docstring in the existing code.
If the custom rule requires docstrings for new functions, this is a real violation.
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/test_viz_cache_key.py
**Line:** 35:35
**Comment:**
*Custom Rule: Add a short docstring to this helper function to describe its purpose and expected behavior.
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| return viz.BaseViz(datasource=datasource, form_data={"viz_type": "table"}) | ||
|
|
||
|
|
||
| def test_no_per_user_opt_in_keys_match_across_users(): |
There was a problem hiding this comment.
Suggestion: Add an explicit return type annotation to this test function (for example, -> None) to comply with the typing rule. [custom_rule]
Severity Level: Minor
Why it matters? 🤔
The test function is defined without an explicit return type annotation.
If the rule requires newly added functions to declare -> None, the existing code violates that rule.
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/test_viz_cache_key.py
**Line:** 46:46
**Comment:**
*Custom Rule: Add an explicit return type annotation to this test function (for example, `-> None`) to comply with the typing rule.
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| assert key_a != key_b | ||
|
|
||
|
|
||
| def test_same_user_same_query_idempotent(): |
There was a problem hiding this comment.
Suggestion: Add a function docstring explaining the scenario this test validates. [custom_rule]
Severity Level: Minor
Why it matters? 🤔
This newly added test function has no docstring in the existing code.
Assuming the custom rule is to document new functions, the violation is present.
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/test_viz_cache_key.py
**Line:** 83:83
**Comment:**
*Custom Rule: Add a function docstring explaining the scenario this test validates.
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|
|
||
|
|
||
| @patch("superset.utils.cache_keys.feature_flag_manager") | ||
| def test_cache_query_by_user_flag_yields_distinct_keys(feature_flag_mock): |
There was a problem hiding this comment.
Suggestion: Add explicit type hints for the function parameter and return type to satisfy the typing requirement for new functions. [custom_rule]
Severity Level: Minor
Why it matters? 🤔
The function has an untyped parameter (feature_flag_mock) and no return annotation.
If the typing rule applies to new functions here, this is a genuine violation.
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/test_viz_cache_key.py
**Line:** 96:96
**Comment:**
*Custom Rule: Add explicit type hints for the function parameter and return type to satisfy the typing requirement for new functions.
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
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #39789 +/- ##
==========================================
+ Coverage 64.39% 64.41% +0.02%
==========================================
Files 2567 2568 +1
Lines 134411 134424 +13
Branches 31203 31203
==========================================
+ Hits 86557 86595 +38
+ Misses 46354 46332 -22
+ Partials 1500 1497 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
sadpandajoe
left a comment
There was a problem hiding this comment.
Clean bug fix — correctly extracts the per-user cache key logic into a shared helper and applies it to the legacy viz.BaseViz.cache_key() path. Good test coverage for both the helper and the viz integration. LGTM.
betodealmeida
left a comment
There was a problem hiding this comment.
We should try to get rid of superset/viz.py, having 2 paths like this is not good.
f41bca7 to
fc62f22
Compare
|
Bito Automatic Review Skipped – PR Already Merged |
SUMMARY
The
/superset/explore_json/endpoint was not respecting per-user caching, which can be enforced via FF and also required for DB connections authenticating with OAuth2.This PR fixes the issue by moving the logic responsible for adding the cache keys to a helper that's used on both flows.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
No UI changes.
TESTING INSTRUCTIONS
Test coverage added. For manual testing:
CACHE_QUERY_BY_USERFF.ADDITIONAL INFORMATION