Repository: litestar-org/litestar

Issue:
docs: update TODO app w/ sqlalchemy tutorial to use autocommitting before send handler.
              > @AgarwalPragy You are correct. By default, the plugin session handler does not automatically commit on a successful response. You can easily change it by using the following `before_send` handler:
> 
> ```python
> from advanced_alchemy.extensions.litestar.plugins.init.config.asyncio import autocommit_before_send_handler
> 
> db_url = "sqlite+aiosqlite:///:memory:"
> app = Litestar(
>     route_handlers=[hello],
>     plugins=[
>         SQLAlchemyPlugin(
>             config=SQLAlchemyAsyncConfig(
>                 connection_string=db_url,
>                 session_dependency_key="transaction",
>                 create_all=True,
>                 alembic_config=AlembicAsyncConfig(target_metadata=orm_registry.metadata),
>                 before_send_handler=autocommit_before_send_handler,
>             ),
>         ),
>     ],
> )
> ```

I'd say this is a documentation bug on our side now.

We should update https://docs.litestar.dev/latest/tutorials/sqlalchemy/3-init-plugin.html to do the same as this (it was written before the autocommit handler was a part of the plugin, IIRC).

_Originally posted by @peterschutt in https://github.com/litestar-org/litestar/issues/2556#issuecomment-1786287414_
            

<!-- POLAR PLEDGE BADGE START -->
---
> [!NOTE]  
> While we are open for sponsoring on [GitHub Sponsors](https://github.com/sponsors/litestar-org/) and 
> [OpenCollective](https://opencollective.com/litestar), we also utilize [Polar.sh](https://polar.sh/) to engage in pledge-based sponsorship.
>
> Check out all issues funded or available for funding [on our Polar.sh Litestar dashboard](https://polar.sh/litestar-org)
> * If you would like to see an issue prioritized, make a pledge towards it!
> * We receive the pledge once the issue is completed & verified
> * This, along with engagement in the community, helps us know which features are a priority to our users.

<a href="https://polar.sh/litestar-org/litestar/issues/2569">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/litestar-org/litestar/issues/2569/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/litestar-org/litestar/issues/2569/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->



Discussion:

Resolving patch:
diff --git a/docs/examples/contrib/sqlalchemy/plugins/tutorial/full_app_with_plugin.py b/docs/examples/contrib/sqlalchemy/plugins/tutorial/full_app_with_plugin.py
--- a/docs/examples/contrib/sqlalchemy/plugins/tutorial/full_app_with_plugin.py
+++ b/docs/examples/contrib/sqlalchemy/plugins/tutorial/full_app_with_plugin.py
@@ -1,5 +1,6 @@
 from typing import AsyncGenerator, List, Optional
 
+from advanced_alchemy.extensions.litestar.plugins.init.config.asyncio import autocommit_before_send_handler
 from sqlalchemy import select
 from sqlalchemy.exc import IntegrityError, NoResultFound
 from sqlalchemy.ext.asyncio import AsyncSession
@@ -71,7 +72,10 @@ async def update_item(item_title: str, data: TodoItem, transaction: AsyncSession
 
 
 db_config = SQLAlchemyAsyncConfig(
-    connection_string="sqlite+aiosqlite:///todo.sqlite", metadata=Base.metadata, create_all=True
+    connection_string="sqlite+aiosqlite:///todo.sqlite",
+    metadata=Base.metadata,
+    create_all=True,
+    before_send_handler=autocommit_before_send_handler,
 )
 
 app = Litestar(


Test patch: