--- /dev/null
+.. change::
+ :tags: bug, orm, asyncio
+ :tickets: 7524
+
+ Added missing method :meth:`_asyncio.AsyncSession.invalidate` to the
+ :class:`_asyncio.AsyncSession` class.
+
"""
return await greenlet_spawn(self.sync_session.close)
+ async def invalidate(self):
+ """Close this Session, using connection invalidation.
+
+ For a complete description, see :meth:`_orm.Session.invalidate`.
+ """
+ return await greenlet_spawn(self.sync_session.invalidate)
+
@classmethod
async def close_all(self):
"""Close all :class:`_asyncio.AsyncSession` sessions."""
from sqlalchemy.testing import is_
from sqlalchemy.testing import is_true
from sqlalchemy.testing import mock
+from sqlalchemy.testing.assertions import is_false
from .test_engine_py3k import AsyncFixture as _AsyncFixture
from ...orm import _fixtures
result = await async_session.execute(select(User))
eq_(result.all(), [])
+ @async_test
+ @testing.requires.independent_connections
+ async def test_invalidate(self, async_session):
+ await async_session.execute(select(1))
+ conn = async_session.sync_session.connection()
+ fairy = conn.connection
+ connection_rec = fairy._connection_record
+
+ is_false(conn.closed)
+ is_false(connection_rec._is_hard_or_soft_invalidated())
+ await async_session.invalidate()
+ is_true(conn.closed)
+ is_true(connection_rec._is_hard_or_soft_invalidated())
+
+ eq_(async_session.in_transaction(), False)
+
class AsyncCascadesTest(AsyncFixture):
run_inserts = None