Skip to content

Commit 2fcaff6

Browse files
author
AidanAbd
committed
fix: allow isolation level to be serializable
1 parent a67bdad commit 2fcaff6

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
dist/
2+
/**/__pycache__/

latch_postgres/postgres.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,21 +627,26 @@ def sqlq(x: str):
627627

628628
# todo(maximsmol): conn resets appear in the startup span and make it last forever
629629
@trace_function(tracer)
630-
async def reset_conn(x: AsyncConnection[object], read_only: bool = False):
630+
async def reset_conn(
631+
x: AsyncConnection[object],
632+
read_only: bool = False,
633+
isolation_level: IsolationLevel = IsolationLevel.SERIALIZABLE,
634+
):
631635
x.prepare_threshold = 0
632636

633637
if x.read_only != read_only:
634638
await x.set_read_only(read_only)
635639

636-
if x.isolation_level != IsolationLevel.SERIALIZABLE:
637-
await x.set_isolation_level(IsolationLevel.SERIALIZABLE)
640+
if x.isolation_level != isolation_level:
641+
await x.set_isolation_level(isolation_level)
638642

639643

640644
# fixme(maximsmol): use autocommit transactions
641645
def get_pool(
642646
config: PostgresConnectionConfig,
643647
application_name: str,
644648
read_only: bool = True,
649+
isolation_level: IsolationLevel = IsolationLevel.SERIALIZABLE,
645650
) -> TracedAsyncConnectionPool:
646651
conn_str = make_conninfo(
647652
host=config.host,
@@ -657,7 +662,11 @@ def get_pool(
657662
max_size=config.pool_size,
658663
timeout=timedelta(seconds=5) / timedelta(seconds=1),
659664
open=False,
660-
configure=functools.partial(reset_conn, read_only=read_only),
661-
reset=functools.partial(reset_conn, read_only=read_only),
665+
configure=functools.partial(
666+
reset_conn, read_only=read_only, isolation_level=isolation_level
667+
),
668+
reset=functools.partial(
669+
reset_conn, read_only=read_only, isolation_level=isolation_level
670+
),
662671
connection_class=LatchAsyncConnection,
663672
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "latch-postgres"
3-
version = "0.1.16"
3+
version = "0.1.17"
44
description = "Postges wrapper for latch python backend services"
55
authors = ["Max Smolin <[email protected]>"]
66
license = "CC0 1.0"

0 commit comments

Comments
 (0)