mirror of
https://github.com/d3vyce/fastapi-toolsets.git
synced 2026-08-05 08:04:08 +00:00
* fix: lock_tables acquires dedicated session to enforce RAII lock boundaries (#261) * fix: make lock_tables generic over session type (#270) * docs: fix zensical warnings * Version 4.0.0 * docs: add v4 migration + fix lock_tables documentation
41 lines
1.2 KiB
Markdown
41 lines
1.2 KiB
Markdown
# Migrating to v4.0
|
|
|
|
This page covers every breaking change introduced in **v4.0** and the steps required to update your code.
|
|
|
|
---
|
|
|
|
## Database
|
|
|
|
### `lock_tables` now takes a `session_maker` instead of a `session`
|
|
|
|
The first argument of `lock_tables` changed from an `AsyncSession` instance to an `async_sessionmaker`.
|
|
The function creates and manages its own **dedicated session** internally, yielding it to the caller.
|
|
|
|
=== "Before (`v3`)"
|
|
|
|
```python
|
|
from fastapi_toolsets.db import lock_tables, LockMode
|
|
|
|
async with lock_tables(session=session, tables=[User, Account]):
|
|
user = await UserCrud.get(session, [User.id == 1])
|
|
user.balance += 100
|
|
|
|
# With a custom lock mode
|
|
async with lock_tables(session, [Order], mode=LockMode.EXCLUSIVE):
|
|
await process_order(session, order_id)
|
|
```
|
|
|
|
=== "Now (`v4`)"
|
|
|
|
```python
|
|
from fastapi_toolsets.db import lock_tables, LockMode
|
|
|
|
async with lock_tables(session_maker=session_maker, tables=[User, Account]) as session:
|
|
user = await UserCrud.get(session, [User.id == 1])
|
|
user.balance += 100
|
|
|
|
# With a custom lock mode
|
|
async with lock_tables(session_maker, [Order], mode=LockMode.EXCLUSIVE) as session:
|
|
await process_order(session, order_id)
|
|
```
|