@@ -32,13 +32,17 @@ async def concurrent_queries(_: Request) -> JSONResponse:
3232 ),
3333 _insert_non_ctx (), # new non context session
3434 _insert_non_ctx_manual (), # new non context session
35+ run_in_new_ctx ( # new context and session with autorollback
36+ _insert_with_exception
37+ ),
38+ return_exceptions = True ,
3539 )
3640 return JSONResponse ({})
3741
3842
3943async def _insert () -> None :
4044 session = await db_session (connection )
41- stmt = insert (ExampleTable ). values ( text = "example_multiple_sessions" )
45+ stmt = insert (ExampleTable )
4246 await session .execute (stmt )
4347
4448
@@ -60,7 +64,7 @@ async def _insert_non_ctx() -> None:
6064 You don't have to use the context to work with sessions at all
6165 """
6266 async with new_non_ctx_atomic_session (connection ) as session :
63- stmt = insert (ExampleTable ). values ( text = "example_multiple_sessions" )
67+ stmt = insert (ExampleTable )
6468 await session .execute (stmt )
6569
6670
@@ -69,6 +73,13 @@ async def _insert_non_ctx_manual() -> None:
6973 You don't have to use the context to work with sessions at all
7074 """
7175 async with new_non_ctx_session (connection ) as session :
72- stmt = insert (ExampleTable ). values ( text = "example_multiple_sessions" )
76+ stmt = insert (ExampleTable )
7377 await session .execute (stmt )
7478 await session .commit ()
79+
80+
81+ async def _insert_with_exception () -> None :
82+ session = await db_session (connection )
83+ stmt = insert (ExampleTable )
84+ await session .execute (stmt )
85+ raise Exception ()
0 commit comments