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: Ensure consistent rollback logic for failed SQL operations #20811

Merged

Conversation

john-bodley
Copy link
Member

SUMMARY

This PR ensures we consistently handle rollbacks when an error occurs. Throughout the code there's inconsistent logic of the form:

try:    
    if commit:
        db.session.commit()
except SQLAlchemyError as ex:
    db.session.rollback()

as well as:

try:    
    if commit:
        db.session.commit()
except SQLAlchemyError as ex:
    if commit:
        db.session.rollback()

This PR—by way of git grep -B 1 rollback—removes the unnecessary if commit checkout before a rollback because we want to rollback any operation which failed—pre commit—in the transaction regardless of whether we're planning to commit, i.e., save the state.

Regarding commits per here it's worth noting that once committed a rollback is not viable.

The transaction can not undo changes after COMMIT execution.

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 requested review from ktmud and dpgaspar July 21, 2022 17:58
@john-bodley john-bodley changed the title fix: Ensure consistent rollback logic fix: Ensure consistent rollback logic for failed SQL operations Jul 21, 2022
@zhaoyongjie zhaoyongjie self-requested a review July 22, 2022 09:32
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.

commit and rollback are mutually exclusive. lgtm. BTW, please don't care about the code coverage ci failure, the master branch has fixed it.

@john-bodley john-bodley merged commit 7a1aa79 into apache:master Jul 25, 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 and removed 🚢 2.1.3 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/S 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants