summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/scoping.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2021-07-27 22:30:06 +0200
committerFederico Caselli <cfederico87@gmail.com>2021-07-28 21:36:14 +0200
commita2e9aca2cf37db94d862c1721a371d00233cec16 (patch)
tree7421751298a3f57630e14c9d171827d6e5b7cc05 /lib/sqlalchemy/orm/scoping.py
parent95648050cfb2afb5bea8558a6246ed3b5360e7fd (diff)
downloadsqlalchemy-a2e9aca2cf37db94d862c1721a371d00233cec16.tar.gz
Deprecate scoped_session usage with async sessions
Deprecate usage of :class:`_orm.scoped_session` with asyncio drivers. When using Asyncio the :class:`_asyncio.async_scoped_session` should be used instead. Fixes: #6746 Change-Id: I540d57a406f59efc37fc61f0e9dfe03f32fe2904
Diffstat (limited to 'lib/sqlalchemy/orm/scoping.py')
-rw-r--r--lib/sqlalchemy/orm/scoping.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/scoping.py b/lib/sqlalchemy/orm/scoping.py
index be16bc911..353caa8fe 100644
--- a/lib/sqlalchemy/orm/scoping.py
+++ b/lib/sqlalchemy/orm/scoping.py
@@ -13,6 +13,7 @@ from ..util import create_proxy_methods
from ..util import ScopedRegistry
from ..util import ThreadLocalRegistry
from ..util import warn
+from ..util import warn_deprecated
__all__ = ["scoped_session", "ScopedSessionMixin"]
@@ -42,9 +43,16 @@ class ScopedSessionMixin(object):
else:
sess = self.session_factory(**kw)
self.registry.set(sess)
- return sess
else:
- return self.registry()
+ sess = self.registry()
+ if not self._support_async and sess._is_asyncio:
+ warn_deprecated(
+ "Using `scoped_session` with asyncio is deprecated and "
+ "will raise an error in a future version. "
+ "Please use `async_scoped_session` instead.",
+ "1.4.23",
+ )
+ return sess
def configure(self, **kwargs):
"""reconfigure the :class:`.sessionmaker` used by this
@@ -116,8 +124,16 @@ class scoped_session(ScopedSessionMixin):
See :ref:`unitofwork_contextual` for a tutorial.
+ ..warning::
+
+ When using :ref:`asyncio_toplevel` the async
+ version :class:`_asyncio.async_scoped_session` should be
+ used instead.
+
"""
+ _support_async = False
+
session_factory = None
"""The `session_factory` provided to `__init__` is stored in this
attribute and may be accessed at a later time. This can be useful when