Take advantage of execute_write_fn(transaction=True)

A bunch of places no longer need to do manual transaction handling
thanks to this change. Refs #2277
This commit is contained in:
Simon Willison 2024-02-17 20:51:19 -08:00
commit 10f9ba1a00
3 changed files with 20 additions and 26 deletions

View file

@ -501,9 +501,8 @@ async def test_execute_write_has_correctly_prepared_connection(db):
@pytest.mark.asyncio
async def test_execute_write_fn_block_false(db):
def write_fn(conn):
with conn:
conn.execute("delete from roadside_attractions where pk = 1;")
row = conn.execute("select count(*) from roadside_attractions").fetchone()
conn.execute("delete from roadside_attractions where pk = 1;")
row = conn.execute("select count(*) from roadside_attractions").fetchone()
return row[0]
task_id = await db.execute_write_fn(write_fn, block=False)
@ -513,9 +512,8 @@ async def test_execute_write_fn_block_false(db):
@pytest.mark.asyncio
async def test_execute_write_fn_block_true(db):
def write_fn(conn):
with conn:
conn.execute("delete from roadside_attractions where pk = 1;")
row = conn.execute("select count(*) from roadside_attractions").fetchone()
conn.execute("delete from roadside_attractions where pk = 1;")
row = conn.execute("select count(*) from roadside_attractions").fetchone()
return row[0]
new_count = await db.execute_write_fn(write_fn)