Releases: krylosov-aa/context-async-sqlalchemy
Release list
2.1.9
before_commit callback
All middlewares accept an optional before_commit parameter — an async callable that is invoked
right before each session with an open transaction is committed.
BeforeCommitCallback = Callable[[AsyncSession], Coroutine[Any, Any, None]]The callback receives the AsyncSession that is about to be committed, so you can inspect its
state and perform side effects such as recording audit
data or capturing a WAL LSN.
async def my_before_commit(session: AsyncSession) -> None:
# called once per session, just before commit
...
add_fastapi_http_db_session_middleware(app, before_commit=my_before_commit)The callback is not called when a session is rolled back.
2.1.8
- New linters have been introduced and checks in existing ones have been strengthened
- Minor improvements in the tests
2.1.7
- Fixed a potential race in session_maker
- Fixed the run_in_new_ctx function. Isolation was working only incidentally via the Task that asyncio.gather wraps each call in
2.1.6
2.1.5
small fix in is_context_initiated, pop_db_session_from_context, get_db_session_from_context
2.1.4
atomic_db_session
There are several options that define how the function will handle
an already open transaction.
current_transaction:
"commit" - commits the open transaction and starts a new one
"rollback" - rolls back the open transaction and starts a new one
"append" - continues using the current transaction and commits it
"raise" - raises an InvalidRequestError
set_test_context
Use auto_close=False if you’re using a test session and transaction
that you close manually elsewhere in your code.
Use auto_close=True if, for example, you want to call a
function in a test that uses a context bypassing the
middleware, and you want all sessions to be closed automatically.
2.0.4
2.0.3
I removed modules from the init that not everyone needs