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

fix(temporary-cache): when user is anonymous #20181

Merged
merged 5 commits into from
May 26, 2022

Conversation

villebro
Copy link
Member

@villebro villebro commented May 25, 2022

SUMMARY

While testing Explore with an anonymous user, I noticed that the explore form data endpoint errored out due to calling get_user_id() on the anonymous user object:

Traceback (most recent call last):
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/flask_appbuilder/api/__init__.py", line 85, in wraps
    return f(self, *args, **kwargs)
  File "/Users/ville/src/superset/superset/utils/log.py", line 245, in wrapper
    value = f(*args, **kwargs)
  File "/Users/ville/src/superset/superset/views/base_api.py", line 83, in wraps
    return f(self, *args, **kwargs)
  File "/Users/ville/src/superset/superset/explore/form_data/api.py", line 117, in post
    key = CreateFormDataCommand(args).run()
  File "/Users/ville/src/superset/superset/explore/form_data/commands/create.py", line 54, in run
    "owner": actor.get_user_id(),
AttributeError: 'AnonymousUserMixin' object has no attribute 'get_user_id'

This PR introduces a new util function get_owner that returns the id if the user is not anonymous, otherwise None, and replaces all direct calls to actor.get_user_id() with get_owner(actor).

In addition, I noticed that TemporaryCache had a lot of references to Chart, Dashboard and Dataset Exceptions, particularly (((Chart))|(Dataset)|(Dashboard))((NotFound)|(AccessDenied))Error. To make it more generic, we introduce a new exception TemporaryCacheResourceNotFoundError and reraise all occurrences of the resource-specific exceptions with the new generic one. Since the integration tests already check for the outcome (400, 403, 404 etc), the tests don't need to be updated.

The return type for the Explore util check_access is also removed, as it isn't needed. The method is expected to raise an exception if access is denied, hence no Optional[bool] is needed. The unit tests are updated accordingly.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

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

@codecov
Copy link

codecov bot commented May 25, 2022

Codecov Report

Merging #20181 (e4bfd2e) into master (ce01ce9) will decrease coverage by 0.03%.
The diff coverage is 84.34%.

❗ Current head e4bfd2e differs from pull request most recent head 095f87b. Consider uploading reports for the commit 095f87b to get more accurate results

@@            Coverage Diff             @@
##           master   #20181      +/-   ##
==========================================
- Coverage   66.44%   66.41%   -0.04%     
==========================================
  Files        1721     1724       +3     
  Lines       64548    64629      +81     
  Branches     6811     6811              
==========================================
+ Hits        42890    42921      +31     
- Misses      19925    19975      +50     
  Partials     1733     1733              
Flag Coverage Δ
hive 53.70% <39.87%> (-0.02%) ⬇️
mysql 82.14% <88.60%> (+<0.01%) ⬆️
postgres 82.20% <88.60%> (+<0.01%) ⬆️
presto ?
python 82.51% <88.60%> (-0.12%) ⬇️
sqlite 81.94% <88.60%> (+<0.01%) ⬆️
unit ?

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

Impacted Files Coverage Δ
...ugin-chart-table/src/DataTable/hooks/useSticky.tsx 4.21% <0.00%> (ø)
...nd/plugins/plugin-chart-table/src/controlPanel.tsx 16.66% <0.00%> (ø)
superset-frontend/src/components/Icons/index.tsx 100.00% <ø> (ø)
...end/src/components/PageHeaderWithActions/index.tsx 90.00% <ø> (ø)
...ponents/ReportModal/HeaderReportDropdown/index.tsx 69.33% <ø> (ø)
...dashboard/components/menu/ShareMenuItems/index.tsx 90.00% <ø> (ø)
superset/constants.py 100.00% <ø> (ø)
.../explore/components/ExploreViewContainer/index.jsx 52.57% <20.00%> (ø)
...tend/plugins/plugin-chart-table/src/TableChart.tsx 39.00% <33.33%> (ø)
superset/temporary_cache/api.py 82.02% <55.55%> (-0.59%) ⬇️
... and 43 more

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 ce01ce9...095f87b. Read the comment docs.

@pull-request-size pull-request-size bot added size/L and removed size/M labels May 25, 2022
@villebro villebro changed the title [WIP] fix(temporary-cache): fail on anonymous user fix(temporary-cache): make work with anonymous user May 25, 2022
@villebro villebro changed the title fix(temporary-cache): make work with anonymous user fix(temporary-cache): when user is anonymous May 25, 2022
Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

I love the changes! Really improved the code's readability and fixed an important bug.

@villebro villebro merged commit 64c4226 into apache:master May 26, 2022
@villebro villebro deleted the villebro/temp-cache-owner branch May 26, 2022 11:45
michael-s-molina pushed a commit that referenced this pull request May 26, 2022
* fix(temporary-cache): fail on anonymous user

* make exceptions generic

* fix test

* remove redundant bool return

* fix unit tests

(cherry picked from commit 64c4226)
philipher29 pushed a commit to ValtechMobility/superset that referenced this pull request Jun 9, 2022
* fix(temporary-cache): fail on anonymous user

* make exceptions generic

* fix test

* remove redundant bool return

* fix unit tests
@mistercrunch mistercrunch added 🍒 1.5.3 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.0.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 lts-v1 preset-io size/L 🍒 1.5.1 🍒 1.5.2 🍒 1.5.3 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants