From 4bf2489847983bbc78780780000408bb09778d51 Mon Sep 17 00:00:00 2001 From: James Ward Date: Tue, 22 Oct 2024 12:27:02 -0400 Subject: [PATCH] fix(sanic): bind session to session class instead of to the session maker (#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 --- advanced_alchemy/extensions/sanic.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/advanced_alchemy/extensions/sanic.py b/advanced_alchemy/extensions/sanic.py index 0476d309..0ae934c2 100644 --- a/advanced_alchemy/extensions/sanic.py +++ b/advanced_alchemy/extensions/sanic.py @@ -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: @@ -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, )