diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-12-26 11:46:42 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-12-26 15:56:12 -0500 |
| commit | 93d5904161c310ffe843ed79e7e7bef13ab11798 (patch) | |
| tree | 378a183c52df036744f902af3000395269c71f2f /lib/sqlalchemy/orm | |
| parent | 0cc8a08262f6b92746a280387282d55beb24fa9d (diff) | |
| download | sqlalchemy-93d5904161c310ffe843ed79e7e7bef13ab11798.tar.gz | |
implement sessionmaker.begin(), scalar() for async session
Added :meth:`_asyncio.AsyncSession.scalar` as well as support for
:meth:`_orm.sessionmaker.begin` to work as an async context manager with
:class:`_asyncio.AsyncSession`. Also added
:meth:`_asyncio.AsyncSession.in_transaction` accessor.
Fixes: #5796
Fixes: #5797
Change-Id: Id3d431421df0f8c38f356469a50a946ba9c38513
Diffstat (limited to 'lib/sqlalchemy/orm')
| -rw-r--r-- | lib/sqlalchemy/orm/session.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 1ec63fa40..a5f0894f6 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1152,6 +1152,12 @@ class Session(_SessionClassMethods): def __exit__(self, type_, value, traceback): self.close() + @util.contextmanager + def _maker_context_manager(self): + with self: + with self.begin(): + yield self + @property @util.deprecated_20( ":attr:`_orm.Session.transaction`", @@ -3969,7 +3975,6 @@ class sessionmaker(_SessionClassMethods): # events can be associated with it specifically. self.class_ = type(class_.__name__, (class_,), {}) - @util.contextmanager def begin(self): """Produce a context manager that both provides a new :class:`_orm.Session` as well as a transaction that commits. @@ -3988,9 +3993,9 @@ class sessionmaker(_SessionClassMethods): """ - with self() as session: - with session.begin(): - yield session + + session = self() + return session._maker_context_manager() def __call__(self, **local_kw): """Produce a new :class:`.Session` object using the configuration |
