Called before the "reset" action occurs for a pooled connection. This event represents when the ``rollback()`` method is called on the DBAPI connection before it is returned to the pool or discarded. A custom "reset" strategy may be implemented using this event hook,
(
self,
dbapi_connection: DBAPIConnection,
connection_record: ConnectionPoolEntry,
reset_state: PoolResetState,
)
| 204 | ), |
| 205 | ) |
| 206 | def reset( |
| 207 | self, |
| 208 | dbapi_connection: DBAPIConnection, |
| 209 | connection_record: ConnectionPoolEntry, |
| 210 | reset_state: PoolResetState, |
| 211 | ) -> None: |
| 212 | """Called before the "reset" action occurs for a pooled connection. |
| 213 | |
| 214 | This event represents |
| 215 | when the ``rollback()`` method is called on the DBAPI connection |
| 216 | before it is returned to the pool or discarded. |
| 217 | A custom "reset" strategy may be implemented using this event hook, |
| 218 | which may also be combined with disabling the default "reset" |
| 219 | behavior using the :paramref:`_pool.Pool.reset_on_return` parameter. |
| 220 | |
| 221 | The primary difference between the :meth:`_events.PoolEvents.reset` and |
| 222 | :meth:`_events.PoolEvents.checkin` events are that |
| 223 | :meth:`_events.PoolEvents.reset` is called not just for pooled |
| 224 | connections that are being returned to the pool, but also for |
| 225 | connections that were detached using the |
| 226 | :meth:`_engine.Connection.detach` method as well as asyncio connections |
| 227 | that are being discarded due to garbage collection taking place on |
| 228 | connections before the connection was checked in. |
| 229 | |
| 230 | Note that the event **is not** invoked for connections that were |
| 231 | invalidated using :meth:`_engine.Connection.invalidate`. These |
| 232 | events may be intercepted using the :meth:`.PoolEvents.soft_invalidate` |
| 233 | and :meth:`.PoolEvents.invalidate` event hooks, and all "connection |
| 234 | close" events may be intercepted using :meth:`.PoolEvents.close`. |
| 235 | |
| 236 | The :meth:`_events.PoolEvents.reset` event is usually followed by the |
| 237 | :meth:`_events.PoolEvents.checkin` event, except in those |
| 238 | cases where the connection is discarded immediately after reset. |
| 239 | |
| 240 | :param dbapi_connection: a DBAPI connection. |
| 241 | The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute. |
| 242 | |
| 243 | :param connection_record: the :class:`.ConnectionPoolEntry` managing |
| 244 | the DBAPI connection. |
| 245 | |
| 246 | :param reset_state: :class:`.PoolResetState` instance which provides |
| 247 | information about the circumstances under which the connection |
| 248 | is being reset. |
| 249 | |
| 250 | .. versionadded:: 2.0 |
| 251 | |
| 252 | .. seealso:: |
| 253 | |
| 254 | :ref:`pool_reset_on_return` |
| 255 | |
| 256 | :meth:`_events.ConnectionEvents.rollback` |
| 257 | |
| 258 | :meth:`_events.ConnectionEvents.commit` |
| 259 | |
| 260 | """ |
| 261 | |
| 262 | def invalidate( |
| 263 | self, |