Skip to content

Commit

Permalink
fix(sanic): bind session to session class instead of to the session m…
Browse files Browse the repository at this point in the history
…aker (#268)

correclty binds session into sanic extension as expected

in the original code, 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

instead, this looks at the sessionmaker `class_` property for adding the sanic dependency
  • Loading branch information
imnotjames authored Oct 22, 2024
1 parent bd9372c commit 4bf2489
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion advanced_alchemy/extensions/sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def __init__(
else self.sqlalchemy_config.get_engine()
)
self.session_maker = self.sqlalchemy_config.create_session_maker()

session_maker = cast("SessionMakerT", self.session_maker)
self.session_class = session_maker.class_

self.app: Sanic

async def _do_commit(self, session: Session | AsyncSession) -> None:
Expand Down Expand Up @@ -181,7 +185,7 @@ async def on_startup(_: Any) -> None:
self.get_sessionmaker_from_request,
)
bootstrap.add_dependency(
type(self.session_maker),
self.session_class,
self.get_session_from_request,
)

Expand Down

0 comments on commit 4bf2489

Please sign in to comment.