@@ -263,3 +263,26 @@ def data_generator():
263263 assert rows [0 ] == {"id" : 1 , "name" : "Alice" , "age" : 30 , "city" : "NYC" }
264264 assert rows [1 ] == {"id" : 2 , "name" : "Bob" , "age" : None , "city" : None }
265265 assert rows [2 ] == {"id" : 3 , "name" : "Charlie" , "age" : 35 , "city" : None }
266+
267+
268+ def test_list_mode_single_record_upsert_last_pk ():
269+ """Test that last_pk is populated correctly for single-record upserts in list mode"""
270+ db = Database (memory = True )
271+
272+ # Create table first
273+ db ["data" ].insert ({"id" : 1 , "name" : "Alice" , "value" : 100 }, pk = "id" )
274+
275+ # Now upsert a single record using list mode
276+ def upsert_data ():
277+ yield ["id" , "name" , "value" ]
278+ yield [1 , "Alice" , 150 ] # Update existing
279+
280+ table = db ["data" ]
281+ table .upsert_all (upsert_data (), pk = "id" )
282+
283+ # Verify the data was updated
284+ rows = list (db ["data" ].rows )
285+ assert rows == [{"id" : 1 , "name" : "Alice" , "value" : 150 }]
286+
287+ # Verify last_pk is populated correctly
288+ assert table .last_pk == 1
0 commit comments