langchain-ai / langgraph

Build resilient language agents as graphs.
https://langchain-ai.github.io/langgraph/
MIT License
5.61k stars 885 forks source link

Encountering RuntimeWarning with AsyncPostgresSaver checkpointer setup in LangGraph #1293

Closed merlin-croain closed 1 month ago

merlin-croain commented 1 month ago

Checked other resources

Example Code

async def get_app(checkpointer: AsyncPostgresSaver) -> CompiledStateGraph:
    app = workflow.compile(checkpointer=checkpointer)
    return app

async def main() -> None:
    connection_kwargs ={
        "autocommit": True,
        "prepare_threshold": 0,
        "row_factory": dict_row,
    }

    async with await AsyncConnection.connect(DATABASE_URL, **connection_kwargs) as conn:
        checkpointer = AsyncPostgresSaver(conn)

        await checkpointer.setup()

        app = await get_app(checkpointer)
        await run(app)

asyncio.run(main())

Error Message and Stack Trace (if applicable)

*/venv/lib/python3.12/site-packages/langgraph/checkpoint/postgres/aio.py:69: RuntimeWarning: coroutine 'AsyncCursor.fetchone' was never awaited
  version = (
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
  File "*/bin/launchable/script", line 348, in <module>
    asyncio.run(main())
  File "*/.pyenv/versions/3.12.3/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "*/.pyenv/versions/3.12.3/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "*/.pyenv/versions/3.12.3/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "*/bin/launchable/script", line 343, in main
    await checkpointer.setup()
  File "*/venv/lib/python3.12/site-packages/langgraph/checkpoint/postgres/aio.py", line 69, in setup
    version = (
              ^
TypeError: 'coroutine' object is not subscriptable

Description

I'm trying to use the new Postgre checkpointer and do the initial setup but I always get the same error. Even using with a connection pool or a connection string.

System Info

System Information

OS: Darwin OS Version: Darwin Kernel Version 23.5.0: Wed May 1 20:14:59 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8122 Python Version: 3.12.3 (main, Jun 5 2024, 17:17:50) [Clang 15.0.0 (clang-1500.3.9.4)]

Package Information

langchain_core: 0.2.29 langchain: 0.2.12 langchain_community: 0.2.11 langsmith: 0.1.98 langchain_milvus: 0.1.4 langchain_openai: 0.1.20 langchain_text_splitters: 0.2.2 langgraph: 0.2.3

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.10.1 async-timeout: Installed. No version info available. dataclasses-json: 0.6.7 jsonpatch: 1.33 langgraph-checkpoint: 1.0.2 numpy: 1.26.4 openai: 1.40.1 orjson: 3.10.6 packaging: 23.2 pydantic: 2.8.2 pymilvus: 2.4.4 PyYAML: 6.0.2 requests: 2.32.3 scipy: 1.14.0 SQLAlchemy: 2.0.32 tenacity: 8.5.0 tiktoken: 0.7.0 typing-extensions: 4.12.2

vbarda commented 1 month ago

@merlin-croain thanks for reporting -- that's a bug, fix incoming!

vbarda commented 1 month ago

This is fixed in 1.0.3!