Close this :class:`_engine.Connection`. This results in a release of the underlying database resources, that is, the DBAPI connection referenced internally. The DBAPI connection is typically restored back to the connection-holding :class:`_pool.Pool` referenced
(self)
| 1235 | self._handle_dbapi_exception(e, None, None, None, None) |
| 1236 | |
| 1237 | def close(self) -> None: |
| 1238 | """Close this :class:`_engine.Connection`. |
| 1239 | |
| 1240 | This results in a release of the underlying database |
| 1241 | resources, that is, the DBAPI connection referenced |
| 1242 | internally. The DBAPI connection is typically restored |
| 1243 | back to the connection-holding :class:`_pool.Pool` referenced |
| 1244 | by the :class:`_engine.Engine` that produced this |
| 1245 | :class:`_engine.Connection`. Any transactional state present on |
| 1246 | the DBAPI connection is also unconditionally released via |
| 1247 | the DBAPI connection's ``rollback()`` method, regardless |
| 1248 | of any :class:`.Transaction` object that may be |
| 1249 | outstanding with regards to this :class:`_engine.Connection`. |
| 1250 | |
| 1251 | This has the effect of also calling :meth:`_engine.Connection.rollback` |
| 1252 | if any transaction is in place. |
| 1253 | |
| 1254 | After :meth:`_engine.Connection.close` is called, the |
| 1255 | :class:`_engine.Connection` is permanently in a closed state, |
| 1256 | and will allow no further operations. |
| 1257 | |
| 1258 | """ |
| 1259 | |
| 1260 | if self._transaction: |
| 1261 | self._transaction.close() |
| 1262 | skip_reset = True |
| 1263 | else: |
| 1264 | skip_reset = False |
| 1265 | |
| 1266 | if self._dbapi_connection is not None: |
| 1267 | conn = self._dbapi_connection |
| 1268 | |
| 1269 | # as we just closed the transaction, close the connection |
| 1270 | # pool connection without doing an additional reset |
| 1271 | if skip_reset: |
| 1272 | cast("_ConnectionFairy", conn)._close_special( |
| 1273 | transaction_reset=True |
| 1274 | ) |
| 1275 | else: |
| 1276 | conn.close() |
| 1277 | |
| 1278 | # There is a slight chance that conn.close() may have |
| 1279 | # triggered an invalidation here in which case |
| 1280 | # _dbapi_connection would already be None, however usually |
| 1281 | # it will be non-None here and in a "closed" state. |
| 1282 | self._dbapi_connection = None |
| 1283 | self.__can_reconnect = False |
| 1284 | |
| 1285 | # special case to handle mypy issue: |
| 1286 | # https://github.com/python/mypy/issues/20651 |
no test coverage detected