prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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 -->
  
  
  </issue>
  <code>
  [start of docs/examples/contrib/sqlalchemy/plugins/tutorial/full_app_with_plugin.py]
  1 from typing import AsyncGenerator, List, Optional
  2 
  3 from sqlalchemy import select
  4 from sqlalchemy.exc import IntegrityError, NoResultFound
  5 from sqlalchemy.ext.asyncio import AsyncSession
  6 from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
  7 
  8 from litestar import Litestar, get, post, put
  9 from litestar.contrib.sqlalchemy.plugins import SQLAlchemyAsyncConfig, SQLAlchemyPlugin
  10 from litestar.exceptions import ClientException, NotFoundException
  11 from litestar.status_codes import HTTP_409_CONFLICT
  12 
  13 
  14 class Base(DeclarativeBase):
  15     ...
  16 
  17 
  18 class TodoItem(Base):
  19     __tablename__ = "todo_items"
  20 
  21     title: Mapped[str] = mapped_column(primary_key=True)
  22     done: Mapped[bool]
  23 
  24 
  25 async def provide_transaction(db_session: AsyncSession) -> AsyncGenerator[AsyncSession, None]:
  26     try:
  27         async with db_session.begin():
  28             yield db_session
  29     except IntegrityError as exc:
  30         raise ClientException(
  31             status_code=HTTP_409_CONFLICT,
  32             detail=str(exc),
  33         ) from exc
  34 
  35 
  36 async def get_todo_by_title(todo_name, session: AsyncSession) -> TodoItem:
  37     query = select(TodoItem).where(TodoItem.title == todo_name)
  38     result = await session.execute(query)
  39     try:
  40         return result.scalar_one()
  41     except NoResultFound as e:
  42         raise NotFoundException(detail=f"TODO {todo_name!r} not found") from e
  43 
  44 
  45 async def get_todo_list(done: Optional[bool], session: AsyncSession) -> List[TodoItem]:
  46     query = select(TodoItem)
  47     if done is not None:
  48         query = query.where(TodoItem.done.is_(done))
  49 
  50     result = await session.execute(query)
  51     return result.scalars().all()
  52 
  53 
  54 @get("/")
  55 async def get_list(transaction: AsyncSession, done: Optional[bool] = None) -> List[TodoItem]:
  56     return await get_todo_list(done, transaction)
  57 
  58 
  59 @post("/")
  60 async def add_item(data: TodoItem, transaction: AsyncSession) -> TodoItem:
  61     transaction.add(data)
  62     return data
  63 
  64 
  65 @put("/{item_title:str}")
  66 async def update_item(item_title: str, data: TodoItem, transaction: AsyncSession) -> TodoItem:
  67     todo_item = await get_todo_by_title(item_title, transaction)
  68     todo_item.title = data.title
  69     todo_item.done = data.done
  70     return todo_item
  71 
  72 
  73 db_config = SQLAlchemyAsyncConfig(
  74     connection_string="sqlite+aiosqlite:///todo.sqlite", metadata=Base.metadata, create_all=True
  75 )
  76 
  77 app = Litestar(
  78     [get_list, add_item, update_item],
  79     dependencies={"transaction": provide_transaction},
  80     plugins=[SQLAlchemyPlugin(db_config)],
  81 )
  82
  [end of docs/examples/contrib/sqlalchemy/plugins/tutorial/full_app_with_plugin.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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 @@
   
   
   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(
  
verification_info: {"golden_diff": "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\n--- a/docs/examples/contrib/sqlalchemy/plugins/tutorial/full_app_with_plugin.py\n+++ b/docs/examples/contrib/sqlalchemy/plugins/tutorial/full_app_with_plugin.py\n@@ -1,5 +1,6 @@\n from typing import AsyncGenerator, List, Optional\n \n+from advanced_alchemy.extensions.litestar.plugins.init.config.asyncio import autocommit_before_send_handler\n from sqlalchemy import select\n from sqlalchemy.exc import IntegrityError, NoResultFound\n from sqlalchemy.ext.asyncio import AsyncSession\n@@ -71,7 +72,10 @@\n \n \n db_config = SQLAlchemyAsyncConfig(\n-    connection_string=\"sqlite+aiosqlite:///todo.sqlite\", metadata=Base.metadata, create_all=True\n+    connection_string=\"sqlite+aiosqlite:///todo.sqlite\",\n+    metadata=Base.metadata,\n+    create_all=True,\n+    before_send_handler=autocommit_before_send_handler,\n )\n \n app = Litestar(\n", "issue": "docs: update TODO app w/ sqlalchemy tutorial to use autocommitting before send handler.\n              > @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:\r\n> \r\n> ```python\r\n> from advanced_alchemy.extensions.litestar.plugins.init.config.asyncio import autocommit_before_send_handler\r\n> \r\n> db_url = \"sqlite+aiosqlite:///:memory:\"\r\n> app = Litestar(\r\n>     route_handlers=[hello],\r\n>     plugins=[\r\n>         SQLAlchemyPlugin(\r\n>             config=SQLAlchemyAsyncConfig(\r\n>                 connection_string=db_url,\r\n>                 session_dependency_key=\"transaction\",\r\n>                 create_all=True,\r\n>                 alembic_config=AlembicAsyncConfig(target_metadata=orm_registry.metadata),\r\n>                 before_send_handler=autocommit_before_send_handler,\r\n>             ),\r\n>         ),\r\n>     ],\r\n> )\r\n> ```\r\n\r\nI'd say this is a documentation bug on our side now.\r\n\r\nWe 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).\r\n\r\n_Originally posted by @peterschutt in https://github.com/litestar-org/litestar/issues/2556#issuecomment-1786287414_\r\n            \n\n<!-- POLAR PLEDGE BADGE START -->\n---\n> [!NOTE]  \n> While we are open for sponsoring on [GitHub Sponsors](https://github.com/sponsors/litestar-org/) and \n> [OpenCollective](https://opencollective.com/litestar), we also utilize [Polar.sh](https://polar.sh/) to engage in pledge-based sponsorship.\n>\n> Check out all issues funded or available for funding [on our Polar.sh Litestar dashboard](https://polar.sh/litestar-org)\n> * If you would like to see an issue prioritized, make a pledge towards it!\n> * We receive the pledge once the issue is completed & verified\n> * This, along with engagement in the community, helps us know which features are a priority to our users.\n\n<a href=\"https://polar.sh/litestar-org/litestar/issues/2569\">\n<picture>\n  <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://polar.sh/api/github/litestar-org/litestar/issues/2569/pledge.svg?darkmode=1\">\n  <img alt=\"Fund with Polar\" src=\"https://polar.sh/api/github/litestar-org/litestar/issues/2569/pledge.svg\">\n</picture>\n</a>\n<!-- POLAR PLEDGE BADGE END -->\n\n", "before_files": [{"content": "from typing import AsyncGenerator, List, Optional\n\nfrom sqlalchemy import select\nfrom sqlalchemy.exc import IntegrityError, NoResultFound\nfrom sqlalchemy.ext.asyncio import AsyncSession\nfrom sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column\n\nfrom litestar import Litestar, get, post, put\nfrom litestar.contrib.sqlalchemy.plugins import SQLAlchemyAsyncConfig, SQLAlchemyPlugin\nfrom litestar.exceptions import ClientException, NotFoundException\nfrom litestar.status_codes import HTTP_409_CONFLICT\n\n\nclass Base(DeclarativeBase):\n    ...\n\n\nclass TodoItem(Base):\n    __tablename__ = \"todo_items\"\n\n    title: Mapped[str] = mapped_column(primary_key=True)\n    done: Mapped[bool]\n\n\nasync def provide_transaction(db_session: AsyncSession) -> AsyncGenerator[AsyncSession, None]:\n    try:\n        async with db_session.begin():\n            yield db_session\n    except IntegrityError as exc:\n        raise ClientException(\n            status_code=HTTP_409_CONFLICT,\n            detail=str(exc),\n        ) from exc\n\n\nasync def get_todo_by_title(todo_name, session: AsyncSession) -> TodoItem:\n    query = select(TodoItem).where(TodoItem.title == todo_name)\n    result = await session.execute(query)\n    try:\n        return result.scalar_one()\n    except NoResultFound as e:\n        raise NotFoundException(detail=f\"TODO {todo_name!r} not found\") from e\n\n\nasync def get_todo_list(done: Optional[bool], session: AsyncSession) -> List[TodoItem]:\n    query = select(TodoItem)\n    if done is not None:\n        query = query.where(TodoItem.done.is_(done))\n\n    result = await session.execute(query)\n    return result.scalars().all()\n\n\n@get(\"/\")\nasync def get_list(transaction: AsyncSession, done: Optional[bool] = None) -> List[TodoItem]:\n    return await get_todo_list(done, transaction)\n\n\n@post(\"/\")\nasync def add_item(data: TodoItem, transaction: AsyncSession) -> TodoItem:\n    transaction.add(data)\n    return data\n\n\n@put(\"/{item_title:str}\")\nasync def update_item(item_title: str, data: TodoItem, transaction: AsyncSession) -> TodoItem:\n    todo_item = await get_todo_by_title(item_title, transaction)\n    todo_item.title = data.title\n    todo_item.done = data.done\n    return todo_item\n\n\ndb_config = SQLAlchemyAsyncConfig(\n    connection_string=\"sqlite+aiosqlite:///todo.sqlite\", metadata=Base.metadata, create_all=True\n)\n\napp = Litestar(\n    [get_list, add_item, update_item],\n    dependencies={\"transaction\": provide_transaction},\n    plugins=[SQLAlchemyPlugin(db_config)],\n)\n", "path": "docs/examples/contrib/sqlalchemy/plugins/tutorial/full_app_with_plugin.py"}]}