Skip to content

Fix wrong default transaction isolation level - #622

Merged
elprans merged 2 commits into
MagicStack:masterfrom
fantix:default-isolation-level
Sep 22, 2020
Merged

Fix wrong default transaction isolation level#622
elprans merged 2 commits into
MagicStack:masterfrom
fantix:default-isolation-level

Conversation

@fantix

@fantixfantix commented Sep 21, 2020

Copy link
Copy Markdown
Member

This fixes the issue when the default_transaction_isolation is not "read committed", transaction(isolation='read_committed') won't start a transaction in "read committed" isolation level.

There're 2 ways to configure a different default transaction isolation level:

  1. SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL serializable;. This SQL changes the default_transaction_isolation setting, and updates the default transaction isolation level too.

  2. Set default_transaction_isolation in postgresql.conf. This is the server-wide default, most servers keep the default read committed value.

server defaultisolation parameterbefore PRafter PR
read committednot setread committedread committed
read committedread committedread committedread committed
read committedrepeatable readrepeatable readrepeatable read
read committedserializableserializableserializable
serializablenot setserializableserializable
serializableread committedserializable ❌read committed
serializablerepeatable readrepeatable readrepeatable read
serializableserializableserializableserializable

As this PR allows true "unset" transaction isolation level, it is impossible to determine if a nested transaction is started with a different isolation level without extra queries, when isolation is "unset" on the outer transaction. Therefore, this PR will raise a warning if the nested transaction specified an isolation level in this case. Update: we are issuing the extra query now.

outer transactionnested transactionbehavior
setconsistent
setinconsistentInterfaceError
setunset
unsetconsistent✅ with extra query
unsetinconsistentInterfaceError with extra query
unsetunset

This fixes the issue when the default_transaction_isolation is
not "read committed", `transaction(isolation='read_committed')`
won't start a transaction in "read committed" isolation level.
Comment threadasyncpg/transaction.py Outdated
@fantix
fantix requested a review from elpransSeptember 22, 2020 04:36
@elprans
elprans merged commit 4a627d5 into MagicStack:masterSep 22, 2020
@fantix
fantix deleted the default-isolation-level branch September 22, 2020 05:17
elprans added a commit that referenced this pull request Dec 21, 2020
A new asyncpg release is here, just in time for Christmas. Notable
additions include Python 3.9 support, support for recently added
PostgreSQL types like `jsonpath`, and last but not least, vastly
improved `executemany()` performance. Importantly, `executemany()` is
also now _atomic_, which means that either all iterations succeed, or
none at all, whereas previously partial results would have remained in
place, unless `executemany()` was called in a transaction.
There is also the usual assortment of improvements and bugfixes, see the
details below.
This is the last release of asyncpg that supports Python 3.5, which is
has reached EOL in September.
Improvements
------------
* Vastly speedup executemany by batching protocol messages (#295)
(by @fantix in 690048d for #295)
* Allow using custom Record class
(by @elprans in db4f1a6 for #577)
* Add Python 3.9 support (#610)
(by @elprans in c05d726 for #610)
* Prefer SSL connections by default (#660)
(by @elprans in 16183aa for #660)
* Add codecs for a bunch of new builtin types (#665)
(by @elprans in b53f038 for #665)
* Expose Pool as asyncpg.Pool (#669)
(by @rugleb in 0e0eb8d for #669)
Fixes
-----
* Add a workaround for bpo-37658
(by @elprans in 2bac166 for #21894)
* Fix wrong default transaction isolation level (#622)
(by @fantix in 4a627d5 for #622)
* Fix set_type_codec() to accept standard SQL type names (#619)
(by @elprans in 68b40cb for #619)
* Ignore custom data codec for internal introspection (#618)
(by @fantix in e064f59 for #618)
* Fix null/NULL quoting in array text encoder (#627)
(by @fantix in 92aa806 for #627)
* Fix link in connect docstring (#653)
(by @samuelcolvin in 8b313bd for #653)
* Make asyncpg work with pyinstaller (#651)
(by @Atem18 in 5ddabb1 for #651)
* Fix possible AttributeError exception in `ConnectionSettings` (#632)
(by @petriborg in 0d23182 for #632)
* Prohibit custom codecs on domains
(by @elprans in 50f964f for #457)
* Raise proper error on anonymous composite input (tuple arguments) (#664)
(by @elprans in 7252dbe for #664)
* Fix incorrect application of custom codecs in some cases (#662)
(by @elprans in 50f65fb for #662)
elprans added a commit that referenced this pull request Dec 21, 2020
A new asyncpg release is here, just in time for Christmas. Notable
additions include Python 3.9 support, support for recently added
PostgreSQL types like `jsonpath`, and last but not least, vastly
improved `executemany()` performance. Importantly, `executemany()` is
also now _atomic_, which means that either all iterations succeed, or
none at all, whereas previously partial results would have remained in
place, unless `executemany()` was called in a transaction.
There is also the usual assortment of improvements and bugfixes, see the
details below.
This is the last release of asyncpg that supports Python 3.5, which is
has reached EOL in September.
Improvements
------------
* Vastly speedup executemany by batching protocol messages (#295)
(by @fantix in 690048d for #295)
* Allow using custom `Record` class
(by @elprans in db4f1a6 for #577)
* Add Python 3.9 support (#610)
(by @elprans in c05d726 for #610)
* Prefer SSL connections by default (#660)
(by @elprans in 16183aa for #660)
* Add codecs for a bunch of new builtin types (#665)
(by @elprans in b53f038 for #665)
* Expose Pool as `asyncpg.Pool` (#669)
(by @rugleb in 0e0eb8d for #669)
Fixes
-----
* Add a workaround for bpo-37658
(by @elprans in 2bac166 for #21894)
* Fix wrong default transaction isolation level (#622)
(by @fantix in 4a627d5 for #622)
* Fix `set_type_codec()` to accept standard SQL type names (#619)
(by @elprans in 68b40cb for #619)
* Ignore custom data codec for internal introspection (#618)
(by @fantix in e064f59 for #618)
* Fix null/NULL quoting in array text encoder (#627)
(by @fantix in 92aa806 for #627)
* Fix link in connect docstring (#653)
(by @samuelcolvin in 8b313bd for #653)
* Make asyncpg work with pyinstaller (#651)
(by @Atem18 in 5ddabb1 for #651)
* Fix possible `AttributeError` exception in `ConnectionSettings` (#632)
(by @petriborg in 0d23182 for #632)
* Prohibit custom codecs on domains
(by @elprans in 50f964f for #457)
* Raise proper error on anonymous composite input (tuple arguments) (#664)
(by @elprans in 7252dbe for #664)
* Fix incorrect application of custom codecs in some cases (#662)
(by @elprans in 50f65fb for #662)
elprans added a commit that referenced this pull request Dec 21, 2020
A new asyncpg release is here, just in time for Christmas. Notable
additions include Python 3.9 support, support for recently added
PostgreSQL types like `jsonpath`, and last but not least, vastly
improved `executemany()` performance. Importantly, `executemany()` is
also now _atomic_, which means that either all iterations succeed, or
none at all, whereas previously partial results would have remained in
place, unless `executemany()` was called in a transaction.
There is also the usual assortment of improvements and bugfixes, see the
details below.
This is the last release of asyncpg that supports Python 3.5, which has
reached EOL in September.
Improvements
------------
* Vastly speedup executemany by batching protocol messages (#295)
(by @fantix in 690048d for #295)
* Allow using custom `Record` class
(by @elprans in db4f1a6 for #577)
* Add Python 3.9 support (#610)
(by @elprans in c05d726 for #610)
* Prefer SSL connections by default (#660)
(by @elprans in 16183aa for #660)
* Add codecs for a bunch of new builtin types (#665)
(by @elprans in b53f038 for #665)
* Expose Pool as `asyncpg.Pool` (#669)
(by @rugleb in 0e0eb8d for #669)
Fixes
-----
* Add a workaround for bpo-37658
(by @elprans in 2bac166 for #21894)
* Fix wrong default transaction isolation level (#622)
(by @fantix in 4a627d5 for #622)
* Fix `set_type_codec()` to accept standard SQL type names (#619)
(by @elprans in 68b40cb for #619)
* Ignore custom data codec for internal introspection (#618)
(by @fantix in e064f59 for #618)
* Fix null/NULL quoting in array text encoder (#627)
(by @fantix in 92aa806 for #627)
* Fix link in connect docstring (#653)
(by @samuelcolvin in 8b313bd for #653)
* Make asyncpg work with pyinstaller (#651)
(by @Atem18 in 5ddabb1 for #651)
* Fix possible `AttributeError` exception in `ConnectionSettings` (#632)
(by @petriborg in 0d23182 for #632)
* Prohibit custom codecs on domains
(by @elprans in 50f964f for #457)
* Raise proper error on anonymous composite input (tuple arguments) (#664)
(by @elprans in 7252dbe for #664)
* Fix incorrect application of custom codecs in some cases (#662)
(by @elprans in 50f65fb for #662)
@elpranselprans mentioned this pull request Dec 21, 2020
elprans added a commit that referenced this pull request Dec 21, 2020
A new asyncpg release is here, just in time for Christmas. Notable
additions include Python 3.9 support, support for recently added
PostgreSQL types like `jsonpath`, and last but not least, vastly
improved `executemany()` performance. Importantly, `executemany()` is
also now _atomic_, which means that either all iterations succeed, or
none at all, whereas previously partial results would have remained in
place, unless `executemany()` was called in a transaction.
There is also the usual assortment of improvements and bugfixes, see the
details below.
This is the last release of asyncpg that supports Python 3.5, which has
reached EOL in September.
Improvements
------------
* Vastly speedup executemany by batching protocol messages (#295)
(by @fantix in 690048d for #295)
* Allow using custom `Record` class
(by @elprans in db4f1a6 for #577)
* Add Python 3.9 support (#610)
(by @elprans in c05d726 for #610)
* Prefer SSL connections by default (#660)
(by @elprans in 16183aa for #660)
* Add codecs for a bunch of new builtin types (#665)
(by @elprans in b53f038 for #665)
* Expose Pool as `asyncpg.Pool` (#669)
(by @rugleb in 0e0eb8d for #669)
Fixes
-----
* Add a workaround for bpo-37658
(by @elprans in 2bac166 for #21894)
* Fix wrong default transaction isolation level (#622)
(by @fantix in 4a627d5 for #622)
* Fix `set_type_codec()` to accept standard SQL type names (#619)
(by @elprans in 68b40cb for #619)
* Ignore custom data codec for internal introspection (#618)
(by @fantix in e064f59 for #618)
* Fix null/NULL quoting in array text encoder (#627)
(by @fantix in 92aa806 for #627)
* Fix link in connect docstring (#653)
(by @samuelcolvin in 8b313bd for #653)
* Make asyncpg work with pyinstaller (#651)
(by @Atem18 in 5ddabb1 for #651)
* Fix possible `AttributeError` exception in `ConnectionSettings` (#632)
(by @petriborg in 0d23182 for #632)
* Prohibit custom codecs on domains
(by @elprans in 50f964f for #457)
* Raise proper error on anonymous composite input (tuple arguments) (#664)
(by @elprans in 7252dbe for #664)
* Fix incorrect application of custom codecs in some cases (#662)
(by @elprans in 50f65fb for #662)
elprans added a commit that referenced this pull request Feb 10, 2021
A new asyncpg release is here.
Notable additions include Python 3.9 support, support for recently added
PostgreSQL types like `jsonpath`, and last but not least, vastly
improved `executemany()` performance. Importantly, `executemany()` is
also now _atomic_, which means that either all iterations succeed, or
none at all, whereas previously partial results would have remained in
place, unless `executemany()` was called in a transaction.
There is also the usual assortment of improvements and bugfixes, see the
details below.
This is the last release of asyncpg that supports Python 3.5, which has
reached EOL last September.
Improvements
------------
* Vastly speedup executemany by batching protocol messages (#295)
(by @fantix in 690048d for #295)
* Allow using custom `Record` class
(by @elprans in db4f1a6 for #577)
* Add Python 3.9 support (#610)
(by @elprans in c05d726 for #610)
* Prefer SSL connections by default (#660)
(by @elprans in 16183aa for #660)
* Add codecs for a bunch of new builtin types (#665)
(by @elprans in b53f038 for #665)
* Expose Pool as `asyncpg.Pool` (#669)
(by @rugleb in 0e0eb8d for #669)
* Avoid unnecessary overhead during connection reset (#648)
(by @kitogo in ff5da5f for #648)
Fixes
-----
* Add a workaround for bpo-37658
(by @elprans in 2bac166 for #21894)
* Fix wrong default transaction isolation level (#622)
(by @fantix in 4a627d5 for #622)
* Fix `set_type_codec()` to accept standard SQL type names (#619)
(by @elprans in 68b40cb for #619)
* Ignore custom data codec for internal introspection (#618)
(by @fantix in e064f59 for #618)
* Fix null/NULL quoting in array text encoder (#627)
(by @fantix in 92aa806 for #627)
* Fix link in connect docstring (#653)
(by @samuelcolvin in 8b313bd for #653)
* Make asyncpg work with pyinstaller (#651)
(by @Atem18 in 5ddabb1 for #651)
* Fix possible `AttributeError` exception in `ConnectionSettings` (#632)
(by @petriborg in 0d23182 for #632)
* Prohibit custom codecs on domains
(by @elprans in 50f964f for #457)
* Raise proper error on anonymous composite input (tuple arguments) (#664)
(by @elprans in 7252dbe for #664)
* Fix incorrect application of custom codecs in some cases (#662)
(by @elprans in 50f65fb for #662)
dmig pushed a commit to dmig/asyncpg that referenced this pull request Feb 22, 2021
A new asyncpg release is here.
Notable additions include Python 3.9 support, support for recently added
PostgreSQL types like `jsonpath`, and last but not least, vastly
improved `executemany()` performance. Importantly, `executemany()` is
also now _atomic_, which means that either all iterations succeed, or
none at all, whereas previously partial results would have remained in
place, unless `executemany()` was called in a transaction.
There is also the usual assortment of improvements and bugfixes, see the
details below.
This is the last release of asyncpg that supports Python 3.5, which has
reached EOL last September.
Improvements
------------
* Vastly speedup executemany by batching protocol messages (MagicStack#295)
(by @fantix in 690048d for MagicStack#295)
* Allow using custom `Record` class
(by @elprans in db4f1a6 for MagicStack#577)
* Add Python 3.9 support (MagicStack#610)
(by @elprans in c05d726 for MagicStack#610)
* Prefer SSL connections by default (MagicStack#660)
(by @elprans in 16183aa for MagicStack#660)
* Add codecs for a bunch of new builtin types (MagicStack#665)
(by @elprans in b53f038 for MagicStack#665)
* Expose Pool as `asyncpg.Pool` (MagicStack#669)
(by @rugleb in 0e0eb8d for MagicStack#669)
* Avoid unnecessary overhead during connection reset (MagicStack#648)
(by @kitogo in ff5da5f for MagicStack#648)
Fixes
-----
* Add a workaround for bpo-37658
(by @elprans in 2bac166 for #21894)
* Fix wrong default transaction isolation level (MagicStack#622)
(by @fantix in 4a627d5 for MagicStack#622)
* Fix `set_type_codec()` to accept standard SQL type names (MagicStack#619)
(by @elprans in 68b40cb for MagicStack#619)
* Ignore custom data codec for internal introspection (MagicStack#618)
(by @fantix in e064f59 for MagicStack#618)
* Fix null/NULL quoting in array text encoder (MagicStack#627)
(by @fantix in 92aa806 for MagicStack#627)
* Fix link in connect docstring (MagicStack#653)
(by @samuelcolvin in 8b313bd for MagicStack#653)
* Make asyncpg work with pyinstaller (MagicStack#651)
(by @Atem18 in 5ddabb1 for MagicStack#651)
* Fix possible `AttributeError` exception in `ConnectionSettings` (MagicStack#632)
(by @petriborg in 0d23182 for MagicStack#632)
* Prohibit custom codecs on domains
(by @elprans in 50f964f for MagicStack#457)
* Raise proper error on anonymous composite input (tuple arguments) (MagicStack#664)
(by @elprans in 7252dbe for MagicStack#664)
* Fix incorrect application of custom codecs in some cases (MagicStack#662)
(by @elprans in 50f65fb for MagicStack#662)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@fantix@elprans