You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "betodealmeida (via GitHub)" <gi...@apache.org> on 2024/08/30 13:27:46 UTC

[PR] feat: allow certain exceptions to commit [superset]

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

   <!---
   Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/
   Example:
   fix(dashboard): load charts correctly
   -->
   
   ### SUMMARY
   <!--- Describe the change below, including rationale and design decisions -->
   
   [SIP-99](https://github.com/apache/superset/issues/25048) introduced in https://github.com/apache/superset/pull/24969 the amazing `@transaction` decorator, which transparently manages transactions in Superset in order to avoid eager commits.
   
   [SIP-85](https://github.com/apache/superset/issues/20300) introduced a mechanism for authenticating to databases via OAuth2, using exceptions to signalize to the frontend from deep in the backend that the user needs to authenticate by following a link. These exceptions are bening, and carry in their `extra` payload (see [SIP-40](https://github.com/apache/superset/issues/9194)) the URL used for authentication, among others.
   
   Because of this, when adding a database that has OAuth2 enabled we need to allow certain exceptions to still commit, while raising them. This allows the database to be created succesfully, while signalizing to the user that they still need to authenticate. This is needed because OAuth2 tokens are stored associated with a database ID, so it must exist a priori.
   
   This PR changes the `@transaction` decorator to allow an optional group of exceptions that should trigger a commit before being re-raised. It's part of a bigger work to add support for OAuth2 to Snowflake, still in progress but already tested end-to-end.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   N/A
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   
   Added unit tests for the `@transaction` decorator, covering the old use cases and the new one.
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] 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
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat: allow certain exceptions to commit [superset]

Posted by "betodealmeida (via GitHub)" <gi...@apache.org>.
betodealmeida closed pull request #30067: feat: allow certain exceptions to commit
URL: https://github.com/apache/superset/pull/30067


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat: allow certain exceptions to commit [superset]

Posted by "betodealmeida (via GitHub)" <gi...@apache.org>.
betodealmeida commented on PR #30067:
URL: https://github.com/apache/superset/pull/30067#issuecomment-2327151403

   @betodealmeida while I recognize it's normally an anti-pattern, no rule is 100% correct ([an example](https://blog.jooq.org/rare-uses-of-a-controlflowexception/) where it can be useful).
   
   For OAuth2 we're basically building a fancy 403 response that has information about how to proceed. We need to let the exception bubble up to the Flask error handler so that we can build a proper SIP-40 compliant error payload, which is what triggers OAuth2 in the frontend side. The benefit of this approach is that we can trigger OAuth2 without having to modify every API that might need it — instead all we need to do is attach a `ErrorMessageWithStackTrace` to the DOM.


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat: allow certain exceptions to commit [superset]

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on PR #30067:
URL: https://github.com/apache/superset/pull/30067#issuecomment-2327061209

   @betodealmeida Not using exceptions to control flow is probably the top 10 best practice. Is it possible to change the code to signalize to the frontend that the user needs to authenticate using other means? I'm really worried about this change as it might generate even more cases where exceptions are used to control flow.
   
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org