Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Sessions to clarify their usage #366

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stefanv
Copy link
Contributor

@stefanv stefanv commented Dec 8, 2023

DBSession has been renamed to HandlerSession.

The following exist now:

  • HandlerSession: a DB session scoped to the current handler; should therefore only be used inside handlers.
  • ThreadSession: a DB session scoped to the current thread; should be used outside of handlers, e.g. when firing off tasks in threads, or inside of services.

A special HandlerSession, with knowledge of the current user, and that verifies permissions on commit, is available as self.Session on the base handler. This is the preferred way of accessing HandlerSession.

To make it easier to get hold of the current engine, the Sessions each have a .engine attribute: HandlerSession.engine.

This avoids having to access the engine as
HandlerSession.session_factory.kw["bind"].

DBSession has been renamed to HandlerSession.

The following exist now:
- HandlerSession: a DB session scoped to the current handler;
  should therefore only be used inside handlers.
- ThreadSession: a DB session scoped to the current thread;
  should be used outside of handlers, e.g. when firing off
  tasks in threads, or inside of services.

A special HandlerSession, with knowledge of the current user, and that
verifies permissions on commit, is available as `self.Session` on the
base handler. This is the *preferred way of accessing* HandlerSession.

To make it easier to get hold of the current engine, the Sessions each
have a `.engine` attribute: `HandlerSession.engine`.

This avoids having to access the engine as
`HandlerSession.session_factory.kw["bind"]`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant