fix: make flask upgrade-db fail on error#32024
fix: make flask upgrade-db fail on error#32024longbingljw wants to merge 1 commit intolanggenius:mainfrom
flask upgrade-db fail on error#32024Conversation
Summary of ChangesHello @longbingljw, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical flaw in the database migration process where Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
I think it is an critical fix.Please have a look at it as soon as possible. @laipz8200 @crazywoola |
|
#31295 |
There was a problem hiding this comment.
Code Review
This pull request correctly addresses an issue where the flask upgrade-db command would silently fail during database migrations, causing CI to pass incorrectly. The change ensures that any exception during migration is caught, logged, and results in a non-zero exit code. My review includes a suggestion to use more idiomatic click constructs for error handling, which improves adherence to command-line tool conventions.
| except Exception as e: | ||
| logger.exception("Failed to execute database migration") | ||
| click.echo(click.style(f"Database migration failed: {e}", fg="red")) | ||
| raise SystemExit(1) |
There was a problem hiding this comment.
This is a good fix to ensure the command fails on error. For better practice with click, I suggest a couple of minor improvements:
- Print error messages to
stderrinstead ofstdoutby addingerr=Truetoclick.echo. - Use
click.Abort()to exit, which is the idiomatic way to abort aclickcommand with an error status. It's more explicit about the intent thanSystemExit(1).
These changes make the command behave more like a standard command-line tool.
| except Exception as e: | |
| logger.exception("Failed to execute database migration") | |
| click.echo(click.style(f"Database migration failed: {e}", fg="red")) | |
| raise SystemExit(1) | |
| except Exception as e: | |
| logger.exception("Failed to execute database migration") | |
| click.echo(click.style(f"Database migration failed: {e}", fg="red"), err=True) | |
| raise click.Abort() |
There was a problem hiding this comment.
I don't think it's necessary to use click.Abort() which is redundant, and regarding the log redirection issue you mentioned, I don't seem to find similar handling elsewhere in the project.
Important
Fixes #<issue number>.Summary
When database migration fails,
flask upgrade-dbsilently swallows the exception and exits with code 0, causing CI to pass even when migrations actually fail.Problem
I tested this with both PostgreSQL and MySQL:
Root Cause
The exception was caught but not re-raised:
except Exception:
logger.exception("Failed to execute database migration")
# Missing: raise or sys.exit(1)
fix #32021
Screenshots
Checklist
make lintandmake type-check(backend) andcd web && npx lint-staged(frontend) to appease the lint gods