Skip to content

Commit

Permalink
Add support for READ UNCOMMITTED (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
benwah committed May 30, 2023
1 parent bf74e88 commit 2f20bae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions asyncpg/connection.py
Expand Up @@ -257,9 +257,9 @@ def transaction(self, *, isolation=None, readonly=False,
:param isolation: Transaction isolation mode, can be one of:
`'serializable'`, `'repeatable_read'`,
`'read_committed'`. If not specified, the behavior
is up to the server and session, which is usually
``read_committed``.
`'read_uncommitted'`, `'read_committed'`. If not
specified, the behavior is up to the server and
session, which is usually ``read_committed``.
:param readonly: Specifies whether or not this transaction is
read-only.
Expand Down
10 changes: 9 additions & 1 deletion asyncpg/transaction.py
Expand Up @@ -19,9 +19,15 @@ class TransactionState(enum.Enum):
FAILED = 4


ISOLATION_LEVELS = {'read_committed', 'serializable', 'repeatable_read'}
ISOLATION_LEVELS = {
'read_committed',
'read_uncommitted',
'serializable',
'repeatable_read',
}
ISOLATION_LEVELS_BY_VALUE = {
'read committed': 'read_committed',
'read uncommitted': 'read_uncommitted',
'serializable': 'serializable',
'repeatable read': 'repeatable_read',
}
Expand Down Expand Up @@ -124,6 +130,8 @@ async def start(self):
query = 'BEGIN'
if self._isolation == 'read_committed':
query += ' ISOLATION LEVEL READ COMMITTED'
elif self._isolation == 'read_uncommitted':
query += ' ISOLATION LEVEL READ UNCOMMITTED'
elif self._isolation == 'repeatable_read':
query += ' ISOLATION LEVEL REPEATABLE READ'
elif self._isolation == 'serializable':
Expand Down
2 changes: 2 additions & 0 deletions tests/test_transaction.py
Expand Up @@ -188,6 +188,7 @@ async def test_isolation_level(self):
isolation_levels = {
None: default_isolation,
'read_committed': 'read committed',
'read_uncommitted': 'read uncommitted',
'repeatable_read': 'repeatable read',
'serializable': 'serializable',
}
Expand All @@ -214,6 +215,7 @@ async def test_nested_isolation_level(self):
set_sql = 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL '
isolation_levels = {
'read_committed': 'read committed',
'read_uncommitted': 'read uncommitted',
'repeatable_read': 'repeatable read',
'serializable': 'serializable',
}
Expand Down

0 comments on commit 2f20bae

Please sign in to comment.