litestar-org/advanced-alchemy

Bug: Sanic extension improperly binds session maker dependency

Closed this issue · 1 comments

Description

The dependency for session maker was defined, and then the dependency for session overwrites it with a session maker as the type. This seems non-ideal -- you can't get the session maker and when you ask for the session maker you get a session object.

It feels like this was a mistake in the sanic extension definition.

URL to code causing the issue

No response

MCVE

session_config = AsyncSessionConfig(expire_on_commit=False)
sqlalchemy_config = SQLAlchemyAsyncConfig(
    connection_string=CONNECTION_STRING,
    session_config=session_config,
)  # Create 'db_session' dependency.
alchemy = SanicAdvancedAlchemy(sqlalchemy_config=sqlalchemy_config)

Extend.register(alchemy)
Extend(app)

@app.get()
async def health(self, request, session_maker: async_sessionmaker):
    print(session_maker)
    return json({"status": "ok"}, 200)

Steps to reproduce

1. Start up server
2. Make request
3. Check `async_sessionmaker`
4. Observe `None`

Screenshots

No response

Logs

No response

Package Version

v0.20.0

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

At the very least we need to drop the extra re-definition.

Ideal solution would be to bind the session classes correctly -- and then update the example code.