from ..util import ScopedRegistry
from ..util import ThreadLocalRegistry
from ..util import warn
+from ..util import warn_deprecated
__all__ = ["scoped_session", "ScopedSessionMixin"]
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
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
from sqlalchemy.orm import mapper
from sqlalchemy.orm import relation
from sqlalchemy.orm import relationship
+from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import Session
+from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import subqueryload
from sqlalchemy.orm import synonym
from sqlalchemy.orm import undefer
from sqlalchemy.testing import AssertsCompiledSQL
from sqlalchemy.testing import eq_
from sqlalchemy.testing import eq_ignore_whitespace
+from sqlalchemy.testing import expect_deprecated
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import is_
from sqlalchemy.testing import is_true
session = self._fixture({self.tables.base_table: base_class_bind})
is_(session.get_bind(self.classes.ConcreteSubClass), testing.db)
+
+
+class DeprecationScopedSessionTest(fixtures.MappedTest):
+ def test_config_errors(self):
+ sm = sessionmaker()
+
+ def go():
+ s = sm()
+ s._is_asyncio = True
+ return s
+
+ Session = scoped_session(go)
+
+ with expect_deprecated(
+ "Using `scoped_session` with asyncio is deprecated and "
+ "will raise an error in a future version. "
+ "Please use `async_scoped_session` instead."
+ ):
+ Session()
+ Session.remove()