Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Deprecate ensure_user_is_set in favor of override_user #20502

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Jun 25, 2022

SUMMARY

The ensure_user_is_set method shares similar logic to override_user. It has logic to only override the user if not set—which I gather is to ensure that it doesn't permanently change the user, however if no user was previously set, setting of a user will persist.

This PR updates the override_user logic to also include a force flag to only override if non-set enabling the ensure_user_is_set method to be removed.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

CI.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@john-bodley john-bodley marked this pull request as ready for review June 25, 2022 17:54
@codecov
Copy link

codecov bot commented Jun 25, 2022

Codecov Report

Merging #20502 (72c71f3) into master (3483446) will decrease coverage by 0.00%.
The diff coverage is 96.07%.

@@            Coverage Diff             @@
##           master   #20502      +/-   ##
==========================================
- Coverage   66.85%   66.85%   -0.01%     
==========================================
  Files        1749     1749              
  Lines       65417    65416       -1     
  Branches     6906     6906              
==========================================
- Hits        43736    43735       -1     
  Misses      19931    19931              
  Partials     1750     1750              
Flag Coverage Δ
hive 53.76% <3.92%> (+<0.01%) ⬆️
mysql 82.40% <96.07%> (-0.01%) ⬇️
postgres 82.47% <96.07%> (-0.01%) ⬇️
presto 53.63% <3.92%> (+<0.01%) ⬆️
python 82.91% <96.07%> (-0.01%) ⬇️
sqlite 82.26% <96.07%> (-0.01%) ⬇️
unit 50.66% <13.72%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/tasks/async_queries.py 90.66% <95.45%> (-0.36%) ⬇️
superset/utils/core.py 90.22% <100.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3483446...72c71f3. Read the comment docs.

@john-bodley john-bodley force-pushed the john-bodley--refactor-ensure_user_is_set branch from 72227d0 to 72c71f3 Compare June 25, 2022 18:06
@@ -76,30 +67,35 @@ def load_chart_data_into_cache(
# pylint: disable=import-outside-toplevel
from superset.charts.data.commands.get_data_command import ChartDataCommand

try:
ensure_user_is_set(job_metadata.get("user_id"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain whether this logic was correct, i.e., should we ensure that job_metadata.get("user_id") is the user performing said actions regardless of whether there is a current user set? Note the override_user context manager will reset back to the current user upon exit.

@benjreinhart it seems you authored #13878 and thus I was hoping you might be able to provide more context, i.e., on line #75 should it be override_user(user) rather than overide_user(user, force=False)?

@@ -1453,23 +1453,27 @@ def get_user_id() -> Optional[int]:


@contextmanager
def override_user(user: Optional[User]) -> Iterator[Any]:
def override_user(user: Optional[User], force: bool = True) -> Iterator[Any]:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The force flag was added for parity, however per my previous comment I'm not sure it's needed.

assert not hasattr(mock_g, "user")

with override_user(user):
mock_g.user = None
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional tests.

Copy link
Member

@zhaoyongjie zhaoyongjie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the improvement! Codes logic is clearer than the original. I'm just curious. When will call the override_user?

@john-bodley
Copy link
Member Author

@zhaoyongjie I introduced override_user in #19914.

@john-bodley john-bodley merged commit 94b3d2f into apache:master Jul 5, 2022
@john-bodley john-bodley deleted the john-bodley--refactor-ensure_user_is_set branch July 5, 2022 17:58
akshatsri pushed a commit to charan1314/superset that referenced this pull request Jul 19, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants