@@ -22,24 +22,24 @@ async def saver(redis_url: str) -> AsyncGenerator[AsyncRedisSaver, None]:
2222@pytest .mark .asyncio
2323async def test_aget_tuple_returns_correct_checkpoint_id (saver : AsyncRedisSaver ):
2424 """Test that aget_tuple returns the correct checkpoint_id when not specified in config.
25-
25+
2626 This test reproduces the issue described in GitHub issue #64 where AsyncRedisSaver
2727 aget_tuple was returning None for checkpoint_id while the sync version worked correctly.
2828 """
2929 # Create a unique thread ID
3030 thread_id = str (uuid .uuid4 ())
31-
31+
3232 # Config with only thread_id and checkpoint_ns (no checkpoint_id)
3333 runnable_config : RunnableConfig = {
3434 "configurable" : {"thread_id" : thread_id , "checkpoint_ns" : "" }
3535 }
36-
36+
3737 # Put several checkpoints
3838 checkpoint_ids = []
3939 for run in range (3 ):
4040 checkpoint_id = str (run )
4141 checkpoint_ids .append (checkpoint_id )
42-
42+
4343 await saver .aput (
4444 {
4545 "configurable" : {
@@ -56,38 +56,40 @@ async def test_aget_tuple_returns_correct_checkpoint_id(saver: AsyncRedisSaver):
5656 },
5757 {},
5858 )
59-
59+
6060 # Get the tuple using the config without checkpoint_id
6161 # This should return the latest checkpoint
6262 get_tuple = await saver .aget_tuple (runnable_config )
63-
63+
6464 # Verify the checkpoint_id is not None and matches the expected value
65- assert get_tuple is not None , f"Expected checkpoint tuple, got None for run { run } "
66-
65+ assert (
66+ get_tuple is not None
67+ ), f"Expected checkpoint tuple, got None for run { run } "
68+
6769 returned_checkpoint_id = get_tuple .config ["configurable" ]["checkpoint_id" ]
6870 assert returned_checkpoint_id is not None , (
6971 f"Expected checkpoint_id to be set, got None for run { run } . "
7072 f"This indicates the bug where aget_tuple returns None for checkpoint_id."
7173 )
72-
74+
7375 # Since we're getting the latest checkpoint each time, it should be the current checkpoint_id
74- assert returned_checkpoint_id == checkpoint_id , (
75- f"Expected checkpoint_id { checkpoint_id } , got { returned_checkpoint_id } for run { run } "
76- )
76+ assert (
77+ returned_checkpoint_id == checkpoint_id
78+ ), f"Expected checkpoint_id { checkpoint_id } , got { returned_checkpoint_id } for run { run } "
7779
7880
7981@pytest .mark .asyncio
8082async def test_aget_tuple_with_explicit_checkpoint_id (saver : AsyncRedisSaver ):
8183 """Test that aget_tuple works correctly when checkpoint_id is explicitly provided."""
8284 # Create a unique thread ID
8385 thread_id = str (uuid .uuid4 ())
84-
86+
8587 # Put several checkpoints
8688 checkpoint_ids = []
8789 for run in range (3 ):
8890 checkpoint_id = str (run )
8991 checkpoint_ids .append (checkpoint_id )
90-
92+
9193 await saver .aput (
9294 {
9395 "configurable" : {
@@ -104,36 +106,38 @@ async def test_aget_tuple_with_explicit_checkpoint_id(saver: AsyncRedisSaver):
104106 },
105107 {},
106108 )
107-
109+
108110 # Test retrieving each checkpoint by explicit checkpoint_id
109111 for checkpoint_id in checkpoint_ids :
110112 config_with_id : RunnableConfig = {
111113 "configurable" : {
112114 "thread_id" : thread_id ,
113115 "checkpoint_id" : checkpoint_id ,
114- "checkpoint_ns" : ""
116+ "checkpoint_ns" : "" ,
115117 }
116118 }
117-
119+
118120 get_tuple = await saver .aget_tuple (config_with_id )
119-
120- assert get_tuple is not None , f"Expected checkpoint tuple, got None for checkpoint_id { checkpoint_id } "
121-
121+
122+ assert (
123+ get_tuple is not None
124+ ), f"Expected checkpoint tuple, got None for checkpoint_id { checkpoint_id } "
125+
122126 returned_checkpoint_id = get_tuple .config ["configurable" ]["checkpoint_id" ]
123- assert returned_checkpoint_id == checkpoint_id , (
124- f"Expected checkpoint_id { checkpoint_id } , got { returned_checkpoint_id } "
125- )
127+ assert (
128+ returned_checkpoint_id == checkpoint_id
129+ ), f"Expected checkpoint_id { checkpoint_id } , got { returned_checkpoint_id } "
126130
127131
128132@pytest .mark .asyncio
129133async def test_aget_tuple_no_checkpoint_returns_none (saver : AsyncRedisSaver ):
130134 """Test that aget_tuple returns None when no checkpoint exists for the thread."""
131135 # Use a thread ID that doesn't exist
132136 thread_id = str (uuid .uuid4 ())
133-
137+
134138 runnable_config : RunnableConfig = {
135139 "configurable" : {"thread_id" : thread_id , "checkpoint_ns" : "" }
136140 }
137-
141+
138142 get_tuple = await saver .aget_tuple (runnable_config )
139- assert get_tuple is None , "Expected None when no checkpoint exists for thread"
143+ assert get_tuple is None , "Expected None when no checkpoint exists for thread"
0 commit comments