Skip to content

Commit

Permalink
🐛 fix(sqla): workaround for nonebot/nonebot2#2475
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgramRipper committed Dec 6, 2023
1 parent 7577996 commit 7da97db
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nonebot_plugin_orm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def _init_orm():
lambda: id(current_event.get(None)),
)

# XXX: workaround for https://github.com/nonebot/nonebot2/issues/2475
event_postprocessor(_clear_scoped_session)
run_postprocessor(_close_scoped_session)


@wraps(lambda: None) # NOTE: for dependency injection
def get_session(**local_kw: Any) -> sa_async.AsyncSession:
Expand All @@ -135,13 +139,13 @@ async def get_scoped_session() -> sa_async.async_scoped_session[sa_async.AsyncSe
]


@event_postprocessor
# @event_postprocessor
def _clear_scoped_session(event: Event) -> None:
with suppress(KeyError):
del _scoped_sessions.registry[id(event)]


@run_postprocessor
# @run_postprocessor
async def _close_scoped_session(event: Event, matcher: Matcher) -> None:
with suppress(KeyError):
session: sa_async.AsyncSession = _scoped_sessions.registry[
Expand Down

0 comments on commit 7da97db

Please sign in to comment.