LonelyVikingMichael / litestar-users

Authentication and user management for the Litestar framework
https://lonelyvikingmichael.github.io/litestar-users/
MIT License
42 stars 12 forks source link

Question: Persisting user changes in the database #64

Closed dshum closed 6 months ago

dshum commented 6 months ago

If you run the code in the examples, the user's changes are not saved in the database. Should I use session.commit() or auto_commit=True myself, and where exactly?

LonelyVikingMichael commented 6 months ago

Apologies, this hasn't been on my radar since I've been using autocommit_before_send_handler from advanced_alchemy https://github.com/jolt-org/advanced-alchemy/blob/main/advanced_alchemy/extensions/litestar/plugins/init/config/asyncio.py#L111

In short, that will commit the current transaction if the status code is 2xx, else rollback.

litestar-users should probably have a way to set the autocommit attribute on the repository.

dshum commented 6 months ago

You mean, add it to SQLAlchemyAsyncConfig?

db_config = SQLAlchemyAsyncConfig(
   ...
    before_send_handler=autocommit_before_send_handler,
)

Thanks for the hint, this will do.