-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
Improve exception handling while failing to connect to a database #3388
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't the rearrangement of the install functions (i.e., by moving the save step after the installation step) leave the possibility of inconsistencies? I.e., if we can't save the model, there could be a problem where the user ends up with Mathesar tooling installed on their user DB, but no working connection to that DB. I'd rather have it the other way around. I.e., we should save, then install, then roll back the save if the installation fails.
This does seem more robust than my previous implementation, I've made the changes accordingly.
I don't think so, we do require an internal database connection at the start for our Django server to make migrations on the target database if the django_db_url is not configured properly the app won't even start. The only way I can think of this happening is when django server is successfully started, then the pg server on which the internal db is hosted is shut down/ not accepting connections and then there is an attempt to add a connection via the UI. I am curious to know what other scenarios you envision when model instances might fail to save? |
Hmmm That's a really good point that the user will definitely at least have some working connection, or the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my specific comment. The db
library needs to stand alone, and shouldn't know about Django model instances.
db/install.py
Outdated
password, | ||
hostname, | ||
port, | ||
db_model, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather avoid having Django classes leak down into the db
library. Eventually, we want to be able to ship this code separately, and we don't want users of that code having to spoof some model class to use this function. (Especially this function, since it's really useful in a python script).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I've reverted the function signature.
…model outside the install func
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I think we're in business here. Nice work, @Anish9901 .
Fixes #3329
Fixes #3361 (part 2)
Fixes #3383
Technical details
This PR globally catches any
OperationalError
that occurs throughout the app. This error is generally caused when an attempt to connect to a database fails, due to reasons such as invalid credentials, db deleted outside mathesar, etc.Example error message: (psycopg2.OperationalError) connection to server at "mathesar_dev_db" (172.18.0.2), port 5435 failed: Connection refused\n\tIs the server running on that host and accepting TCP/IP connections?
Checklist
Update index.md
).develop
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin