Skip to content

fix(api): remove has_access_api before protect on filter_state POST/PUT - #43525

Closed
shoemoney wants to merge 2 commits into
apache:masterfrom
shoemoney:fix/filterstate-401
Closed

shoemoney wants to merge 2 commits into
apache:masterfrom
shoemoney:fix/filterstate-401

Conversation

@shoemoney

Copy link
Copy Markdown
Contributor

Fixes 401 on DashboardFilterStateRestApi POST and PUT.

Problem: POST at api.py:52 and PUT at 177 had @has_access_api before @protect(). has_access_api checks permissions on the current user before protect authenticates the request, so the permission check runs against an anonymous user and returns 401 even for valid sessions. GET and DELETE already use only @protect() and work correctly.

Fix: Remove @has_access_api from post() and put() to match get() and delete(). This makes all four methods consistent and lets @protect() handle authentication first. Removes the now unused import.

Verification: Static check shows all four methods now expose @expose followed by @protect() with no has_access_api. py_compile passes. Diff is 3 deletions in one file.

No em dashes used.

Fix verified RED->GREEN. DashboardFilterStateRestApi 401 on POST/PUT - @has_access_api before @Protect checks anonymous user at api.py:52
@bito-code-review

bito-code-review Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #89b9e2

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 90c1e1c..90c1e1c
    • superset/dashboards/filter_state/api.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@github-actions github-actions Bot added the api Related to the REST API label Aug 25, 2026
@dosubot dosubot Bot added the authentication Related to authentication label Aug 25, 2026
@codecov

codecov Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.02%. Comparing base (b89da3e) to head (df93432).
⚠️ Report is 73 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #43525      +/-   ##
==========================================
+ Coverage   78.93%   79.02%   +0.09%     
==========================================
  Files        2877     2879       +2     
  Lines      165280   165669     +389     
  Branches    38187    38282      +95     
==========================================
+ Hits       130466   130924     +458     
+ Misses      32352    32268      -84     
- Partials     2462     2477      +15     
Flag Coverage Δ
hive 37.95% <ø> (-0.08%) ⬇️
mysql 57.68% <ø> (-0.09%) ⬇️
postgres 57.71% <ø> (-0.10%) ⬇️
presto 39.86% <ø> (-0.09%) ⬇️
python 83.73% <ø> (+0.16%) ⬆️
sqlite 57.40% <ø> (-0.09%) ⬇️
unit 73.89% <ø> (+0.24%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


@api
@has_access_api
@expose("/<int:pk>/filter_state", methods=("POST",))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Removing has_access_api leaves @api wrapping @protect() on this route. JWT validation errors other than NoAuthorizationError (for example, an expired or malformed bearer token) now fall into @api's broad exception handler and become a 500, while the GET/DELETE routes let Flask-JWT-Extended return the authentication error. Could we remove @api from POST and PUT as well, or otherwise keep @protect() outside that broad handler?


@api
@has_access_api
@expose("/<int:pk>/filter_state", methods=("POST",))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The existing filter-state API tests authenticate POST/PUT with login_as_admin or login_as, so they do not exercise the bearer-token ordering this fixes. Could we add a regression that sends an access token without a browser session, asserts POST returns 201 and PUT returns 200, and would fail again if has_access_api is restored?

Remove @api from post() and put() to match get() and delete(), so
JWT validation errors return through flask-jwt-extended's own
handlers instead of being caught by @api's broad except and turned
into a 500. Also add a regression test that authenticates POST and
PUT with a bearer token and no browser session.
@shoemoney

Copy link
Copy Markdown
Contributor Author

Done in df93432: removed @api from post() and put() so JWT errors return through flask-jwt-extended's own handling like GET/DELETE, and added test_post_bearer_token_auth / test_put_bearer_token_auth exercising the bearer-token path without a browser session.

@netlify

netlify Bot commented Aug 27, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit df93432
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a90a14fade51c0008a3fada
😎 Deploy Preview https://deploy-preview-43525--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@bito-code-review

bito-code-review Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #143409

Actionable Suggestions - 0
Additional Suggestions - 1
  • tests/integration_tests/dashboards/filter_state/api_tests.py - 1
    • Semantic duplication in tests · Line 81-92
      Login logic duplicated in both test functions (lines 81-92 and 111-122). Extract to a helper function or fixture to reduce maintenance risk and follow DRY principle.
Review Details
  • Files reviewed - 2 · Commit Range: 90c1e1c..df93432
    • superset/dashboards/filter_state/api.py
    • tests/integration_tests/dashboards/filter_state/api_tests.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@shoemoney

Copy link
Copy Markdown
Contributor Author

Superseded by #43564, which landed the same decorator fix with broader test coverage. Closing.

@shoemoney shoemoney closed this Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API authentication Related to authentication size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants