Skip to content

Expose prepare_threshold parameter in AsyncPostgresSaver.from_conn_string() #6705

@niilooy

Description

@niilooy

Privileged issue

  • I am a LangGraph maintainer, or was asked directly by a LangGraph maintainer to create an issue here.

Issue Content

Problem

When using AsyncPostgresSaver.from_conn_string() with external connection poolers (e.g., Google Cloud SQL connection pooler, PgBouncer in transaction mode), users encounter "prepared statement does not exist" errors:

prepared statement "_pg3_3" does not exist

This occurs because prepare_threshold=0 is hardcoded, which still uses the extended query protocol. Setting prepare_threshold=None resolves the issue.

Proposed Solution

Expose prepare_threshold as an optional parameter:

@classmethod
@asynccontextmanager
async def from_conn_string(
    cls,
    conn_string: str,
    *,
    pipeline: bool = False,
    serde: SerializerProtocol | None = None,
    prepare_threshold: int | None = 0,  # New parameter
) -> AsyncIterator[AsyncPostgresSaver]:

Current Workaround

from psycopg import AsyncConnection
from psycopg.rows import dict_row
from langgraph.checkpoint.postgres import AsyncPostgresSaver

async with await AsyncConnection.connect(
    conn_string, autocommit=True, prepare_threshold=None, row_factory=dict_row
) as conn:
    checkpointer = AsyncPostgresSaver(conn)

Additional Context

This applies to PostgresSaver, ShallowPostgresSaver, and AsyncShallowPostgresSaver as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions