-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
postgres.CopyToTable: Robustize resources cleanup #3072
Open
LinqLover
wants to merge
9
commits into
spotify:master
Choose a base branch
from
LinqLover:postgres-robustize-connections
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
postgres.CopyToTable: Robustize resources cleanup #3072
LinqLover
wants to merge
9
commits into
spotify:master
from
LinqLover:postgres-robustize-connections
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Instead of a generic exception, raise a specific ValueError. The former is considered an anti-pattern because generic exceptions are harder to handle.
Make sure to rollback and close connections as well as to release cursors when an error occurs during CopyToTable.copy(). This can happen, for example, when rows have an invalid format or the method is overriden in a subclass. Tests are added, too (see DailyCopyToTableTest.test_cleanup_on_error()).
LinqLover
commented
Apr 15, 2021
lallea
reviewed
Apr 15, 2021
lallea
reviewed
Apr 15, 2021
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If closed, you may revisit when your time allows and reopen! Thank you for your contributions. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to make connections using the
contrib.postgres
module more robust. If an error occurs during copying the rows, psycopg2 objects previously could be left opened without a proper clean-up, causing further connection attempts to the database to fail as well (psycopg2.errors.ObjectInUse
).By ensuring proper use of try...catch blocks and context managers, issues of this kind should be fixed now. Also, this PR includes regression tests.
For more information about releasing psycopg2 objects, visit: https://www.psycopg.org/docs/usage.html#with-statement
LBNL, a more precise exception class is used in the default
copy()
implementation ofCopyToTable
(f66534c).Kind of replaces #2934, which I unfortunately never had managed to complete.
Preferably please squash when merging.