Skip to content
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

Add support for READ UNCOMMITTED #1039

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions asyncpg/connection.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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