Close all database connections owned by this context. This is called automatically when exiting the async context manager. Also clears the global fallback if this context was set as global.
(self)
| 468 | return self.connections.get(connection_name) |
| 469 | |
| 470 | async def close_connections(self) -> None: |
| 471 | """ |
| 472 | Close all database connections owned by this context. |
| 473 | |
| 474 | This is called automatically when exiting the async context manager. |
| 475 | Also clears the global fallback if this context was set as global. |
| 476 | """ |
| 477 | global _global_context |
| 478 | if self._connections is not None: |
| 479 | # Only close if connections were actually initialized |
| 480 | if self._connections._db_config is not None: |
| 481 | await self._connections.close_all(discard=True) |
| 482 | self._connections = None |
| 483 | # Clear global context if this context was set as the global fallback |
| 484 | if _global_context is self: |
| 485 | _global_context = None |
| 486 | |
| 487 | def __enter__(self) -> TortoiseContext: |
| 488 | """ |