Repository: litestar-org/litestar

Issue:
Flaky test
I think this is a flaky test failure:

```python
 ____________________ test_sqlalchemy_backend_delete_expired ____________________

sqlalchemy_session_backend = <starlite.middleware.session.sqlalchemy_backend.SQLAlchemyBackend object at 0x7f9210794cc0>

    async def test_sqlalchemy_backend_delete_expired(sqlalchemy_session_backend: "SQLAlchemyBackend") -> None:
        await sqlalchemy_session_backend.set("foo", generate_session_data())
        await sqlalchemy_session_backend.set("bar", generate_session_data())
    
        session = sqlalchemy_session_backend._create_sa_session()
        model = sqlalchemy_session_backend.config.model
        session.execute(
            sa.update(model)
            .where(model.session_id == "foo")
            .values(expires=datetime.datetime.utcnow() - datetime.timedelta(days=60))
        )
        await sqlalchemy_session_backend.delete_expired()
    
>       assert not await sqlalchemy_session_backend.get("foo")
E       assert not b'{"47c49f1fa0a29b0e994338a22e32b3c79ca0391a4e55205dac411f173e7e1efe":"8cbd4cf924a42dcb80965706b0fad6af6f9afabc2711365cbe3ba20cdb8ce0c5"}'

tests/middleware/session/test_server_backends.py:130: AssertionError
```
Flaky test
I think this is a flaky test failure:

```python
 ____________________ test_sqlalchemy_backend_delete_expired ____________________

sqlalchemy_session_backend = <starlite.middleware.session.sqlalchemy_backend.SQLAlchemyBackend object at 0x7f9210794cc0>

    async def test_sqlalchemy_backend_delete_expired(sqlalchemy_session_backend: "SQLAlchemyBackend") -> None:
        await sqlalchemy_session_backend.set("foo", generate_session_data())
        await sqlalchemy_session_backend.set("bar", generate_session_data())
    
        session = sqlalchemy_session_backend._create_sa_session()
        model = sqlalchemy_session_backend.config.model
        session.execute(
            sa.update(model)
            .where(model.session_id == "foo")
            .values(expires=datetime.datetime.utcnow() - datetime.timedelta(days=60))
        )
        await sqlalchemy_session_backend.delete_expired()
    
>       assert not await sqlalchemy_session_backend.get("foo")
E       assert not b'{"47c49f1fa0a29b0e994338a22e32b3c79ca0391a4e55205dac411f173e7e1efe":"8cbd4cf924a42dcb80965706b0fad6af6f9afabc2711365cbe3ba20cdb8ce0c5"}'

tests/middleware/session/test_server_backends.py:130: AssertionError
```


Discussion:
Ugh, this again. I thought I fixed it last time. Looks like I did not. I'll take care of it.
Thanks! I really didn't look at it at all, just dumped it here so I didn't forget about it, apologies if a dup. Actually ran into it twice today.
Well, if you encountered it again it's not a dupe! 
Turns out it's not an issue with the tests at all. It was a bug that hid itself very well and only coincidentally passed tests because of how the used SQLite driver works
Ugh, this again. I thought I fixed it last time. Looks like I did not. I'll take care of it.
Thanks! I really didn't look at it at all, just dumped it here so I didn't forget about it, apologies if a dup. Actually ran into it twice today.
Well, if you encountered it again it's not a dupe! 
Turns out it's not an issue with the tests at all. It was a bug that hid itself very well and only coincidentally passed tests because of how the used SQLite driver works

Resolving patch:
diff --git a/starlite/middleware/session/sqlalchemy_backend.py b/starlite/middleware/session/sqlalchemy_backend.py
--- a/starlite/middleware/session/sqlalchemy_backend.py
+++ b/starlite/middleware/session/sqlalchemy_backend.py
@@ -199,6 +199,7 @@ async def delete_expired(self) -> None:
         """
         async with self._create_sa_session() as sa_session:
             await sa_session.execute(sa.delete(self._model).where(self._model.expired))
+            await sa_session.commit()
 
 
 class SQLAlchemyBackend(BaseSQLAlchemyBackend[SASession]):
@@ -290,6 +291,7 @@ async def delete_all(self) -> None:
     def _delete_expired_sync(self) -> None:
         sa_session = self._create_sa_session()
         sa_session.execute(sa.delete(self._model).where(self._model.expired))
+        sa_session.commit()
 
     async def delete_expired(self) -> None:
         """Delete all expired session from the database.


Test patch: