Skip to content

Commit 9ed48d1

Browse files
committed
docs fix
1 parent 93a1177 commit 9ed48d1

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ from contextlib import asynccontextmanager
110110
from typing import Any, AsyncGenerator
111111
from fastapi import FastAPI
112112

113-
from .database import master
113+
from database import master
114114

115115

116116
@asynccontextmanager
@@ -195,8 +195,8 @@ from sqlalchemy import insert
195195

196196
from context_async_sqlalchemy import db_session
197197

198-
from ..database import master
199-
from ..models import ExampleTable
198+
from database import master
199+
from models import ExampleTable
200200

201201

202202
async def handler_with_db_session() -> None:

exmaples/fastapi_example/routes/multiple_session_usage.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
close_db_session,
66
commit_db_session,
77
db_session,
8+
new_non_ctx_atomic_session,
9+
new_non_ctx_session,
810
run_in_new_ctx,
911
)
1012
from sqlalchemy import insert
@@ -21,9 +23,8 @@ async def handler_multiple_sessions() -> None:
2123
await asyncio.gather(
2224
run_in_new_ctx(_insert),
2325
run_in_new_ctx(_insert_manual),
24-
run_in_new_ctx(_insert),
25-
run_in_new_ctx(_insert_manual),
26-
run_in_new_ctx(_insert),
26+
_insert_non_ctx(),
27+
_insert_non_ctx_manual(),
2728
)
2829

2930

@@ -41,3 +42,16 @@ async def _insert_manual() -> None:
4142

4243
# You can manually close the session if you want, but it is not necessary
4344
await close_db_session(master)
45+
46+
47+
async def _insert_non_ctx() -> None:
48+
async with new_non_ctx_atomic_session(master) as session:
49+
stmt = insert(ExampleTable).values(text="example_multiple_sessions")
50+
await session.execute(stmt)
51+
52+
53+
async def _insert_non_ctx_manual() -> None:
54+
async with new_non_ctx_session(master) as session:
55+
stmt = insert(ExampleTable).values(text="example_multiple_sessions")
56+
await session.execute(stmt)
57+
await session.commit()

exmaples/fastapi_example/tests/non_transactional/test_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async def test_example_multiple_sessions(
9898

9999
result = await db_session_test.execute(select(ExampleTable))
100100
rows = result.scalars().all()
101-
assert len(rows) == 5
101+
assert len(rows) == 4
102102
for row in rows:
103103
assert row.text == "example_multiple_sessions"
104104

0 commit comments

Comments
 (0)