This repository was archived by the owner on Aug 19, 2025. It is now read-only.
Fix connection leak when transaction commit/rollback raise an exception#498
Open
masipcat wants to merge 6 commits intoencode:masterfrom
Open
Fix connection leak when transaction commit/rollback raise an exception#498masipcat wants to merge 6 commits intoencode:masterfrom
masipcat wants to merge 6 commits intoencode:masterfrom
Conversation
Contributor
|
Hi, thanks for the PR. |
Author
|
Yeah no problem I'll add a test |
masipcat
commented
Jul 29, 2022
Comment on lines
+554
to
+570
| async with Database(database_url) as database: | ||
| with pytest.raises(Exception) as excinfo: | ||
| async with database.connection() as connection: | ||
| await connection.execute( | ||
| """ | ||
| CREATE TABLE test (id integer PRIMARY KEY INITIALLY DEFERRED); | ||
| """ | ||
| ) | ||
| async with connection.transaction(): | ||
| await connection.execute("insert into test (id) values (1)") | ||
| await connection.execute("insert into test (id) values (1)") | ||
|
|
||
| # During transaction.commit() postgres will raise this exception: | ||
| # asyncpg.exceptions.UniqueViolationError: duplicate key value violates unique constraint "test_pkey" | ||
| # DETAIL: Key (id)=(1) already exists. | ||
| assert "unique constraint" in str(excinfo.value) | ||
| assert connection._connection_counter == 0 |
Author
There was a problem hiding this comment.
@aminalaee I think this test it's only valid for postgresql. Is there a way to skip for other databases?
Contributor
There was a problem hiding this comment.
Yeah sure,
databases/tests/test_databases.py
Line 482 in 6a52a4a
aminalaee
reviewed
Jul 29, 2022
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 fixes the following case: