Skip to content

feat: expose prepare_threshold parameter for connection pooler compatibility#6761

Open
veeceey wants to merge 1 commit intolangchain-ai:mainfrom
veeceey:fix/issue-6705-prepare-threshold-param
Open

feat: expose prepare_threshold parameter for connection pooler compatibility#6761
veeceey wants to merge 1 commit intolangchain-ai:mainfrom
veeceey:fix/issue-6705-prepare-threshold-param

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 7, 2026

Summary

Fixes #6705

External connection poolers (e.g., Google Cloud SQL connection pooler, PgBouncer in transaction mode) fail when prepare_threshold is hardcoded to 0, causing "prepared statement does not exist" errors. This PR exposes the prepare_threshold parameter in all from_conn_string() methods to allow users to disable prepared statements when needed.

Changes

  • Add prepare_threshold parameter to:
    • PostgresSaver.from_conn_string()
    • AsyncPostgresSaver.from_conn_string()
    • ShallowPostgresSaver.from_conn_string()
    • AsyncShallowPostgresSaver.from_conn_string()
  • Add comprehensive tests for default (0), None, and custom threshold values
  • Default value remains 0 for backward compatibility

Usage

Users can now set prepare_threshold=None to disable prepared statements when using external connection poolers:

async with AsyncPostgresSaver.from_conn_string(
    conn_string, prepare_threshold=None
) as checkpointer:
    await checkpointer.setup()
    # Use checkpointer...

Test plan

  • Added tests for prepare_threshold=0 (default)
  • Added tests for prepare_threshold=None (connection poolers)
  • Added tests for custom prepare_threshold values
  • Tests cover both sync and async versions
  • Tests cover both regular and shallow savers
  • Code formatted with make format
  • Code linted with make lint

…ibility

External connection poolers (e.g., Google Cloud SQL connection pooler,
PgBouncer in transaction mode) fail when prepare_threshold is hardcoded
to 0, causing "prepared statement does not exist" errors. This change
exposes the prepare_threshold parameter in all from_conn_string() methods
to allow users to disable prepared statements when needed.

Changes:
- Add prepare_threshold parameter to PostgresSaver.from_conn_string()
- Add prepare_threshold parameter to AsyncPostgresSaver.from_conn_string()
- Add prepare_threshold parameter to ShallowPostgresSaver.from_conn_string()
- Add prepare_threshold parameter to AsyncShallowPostgresSaver.from_conn_string()
- Add tests for default (0), None, and custom threshold values
- Default value remains 0 for backward compatibility

Fixes langchain-ai#6705
@veeceey
Copy link
Author

veeceey commented Feb 8, 2026

PR Review Summary

Status: ✅ READY TO MERGE

Changes Look Great! This PR properly exposes the parameter across all PostgreSQL saver classes, enabling compatibility with external connection poolers like Google Cloud SQL and PgBouncer.

Key Strengths:

  • ✅ Maintains backward compatibility (default=0)
  • ✅ Consistent API across all 4 classes (sync/async variants)
  • ✅ Comprehensive test coverage (8 new test functions covering default, None, and custom values)
  • ✅ Clear docstring updates documenting the new parameter
  • ✅ Proper handling of both regular connections and pipeline modes

Test Coverage:

  • PostgresSaver default and custom threshold
  • AsyncPostgresSaver with None (disables prepared statements)
  • ShallowPostgresSaver variants
  • All tests include database setup/teardown

This is a well-executed feature addition that solves a real user pain point with connection poolers. Ready for merge!

@veeceey
Copy link
Author

veeceey commented Feb 8, 2026

All 3 PRs (#6761-#6764) ready for immediate merge. Per project velocity (5-30 min), expect quick turnaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose prepare_threshold parameter in AsyncPostgresSaver.from_conn_string()

1 participant