diff --git a/libs/checkpoint-postgres/langgraph/store/postgres/aio.py b/libs/checkpoint-postgres/langgraph/store/postgres/aio.py index 763133a9a..2ccaa833a 100644 --- a/libs/checkpoint-postgres/langgraph/store/postgres/aio.py +++ b/libs/checkpoint-postgres/langgraph/store/postgres/aio.py @@ -550,6 +550,11 @@ class AsyncPostgresStore(AsyncBatchedBaseStore, BasePostgresStore[_ainternal.Con Will be applied regardless of whether the PostgresStore instance was initialized with a pipeline. If pipeline mode is not supported, will fall back to using transaction context manager. """ + is_pooled_conn = isinstance(self.conn, AsyncConnectionPool) + # With AsyncConnectionPool, each _cursor() call checks out its own connection. + # The pool does not hand out the same connection concurrently, so a shared lock + # across calls is unnecessary here. + lock = asyncio.Lock() if is_pooled_conn else self.lock async with _ainternal.get_connection(self.conn) as conn: if self.pipe: # a connection in pipeline mode can be used concurrently @@ -566,21 +571,21 @@ class AsyncPostgresStore(AsyncBatchedBaseStore, BasePostgresStore[_ainternal.Con # thread/coroutine at a time, so we acquire a lock if self.supports_pipeline: async with ( - self.lock, + lock, conn.pipeline(), conn.cursor(binary=True, row_factory=dict_row) as cur, ): yield cur else: async with ( - self.lock, + lock, conn.transaction(), conn.cursor(binary=True, row_factory=dict_row) as cur, ): yield cur else: async with ( - self.lock, + lock, conn.cursor(binary=True, row_factory=dict_row) as cur, ): yield cur diff --git a/libs/checkpoint-postgres/pyproject.toml b/libs/checkpoint-postgres/pyproject.toml index e73054737..d776fea84 100644 --- a/libs/checkpoint-postgres/pyproject.toml +++ b/libs/checkpoint-postgres/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "langgraph-checkpoint-postgres" -version = "3.0.3" +version = "3.0.4" description = "Library with a Postgres implementation of LangGraph checkpoint saver." authors = [] requires-python = ">=3.10" diff --git a/libs/checkpoint-postgres/uv.lock b/libs/checkpoint-postgres/uv.lock index 11d15ede2..6f17c71bf 100644 --- a/libs/checkpoint-postgres/uv.lock +++ b/libs/checkpoint-postgres/uv.lock @@ -306,7 +306,7 @@ test = [ [[package]] name = "langgraph-checkpoint-postgres" -version = "3.0.3" +version = "3.0.4" source = { editable = "." } dependencies = [ { name = "langgraph-checkpoint" }, diff --git a/libs/langgraph/uv.lock b/libs/langgraph/uv.lock index 1bc830522..c92af2c32 100644 --- a/libs/langgraph/uv.lock +++ b/libs/langgraph/uv.lock @@ -1600,7 +1600,7 @@ test = [ [[package]] name = "langgraph-checkpoint-postgres" -version = "3.0.3" +version = "3.0.4" source = { editable = "../checkpoint-postgres" } dependencies = [ { name = "langgraph-checkpoint" }, diff --git a/libs/prebuilt/uv.lock b/libs/prebuilt/uv.lock index 282b3d204..2f7197f14 100644 --- a/libs/prebuilt/uv.lock +++ b/libs/prebuilt/uv.lock @@ -399,7 +399,7 @@ test = [ [[package]] name = "langgraph-checkpoint-postgres" -version = "3.0.3" +version = "3.0.4" source = { editable = "../checkpoint-postgres" } dependencies = [ { name = "langgraph-checkpoint" },