Guarantee that a connection to the database is established.
(self)
| 269 | |
| 270 | @async_unsafe |
| 271 | def ensure_connection(self): |
| 272 | """Guarantee that a connection to the database is established.""" |
| 273 | if self.connection is None: |
| 274 | if self.in_atomic_block and self.closed_in_transaction: |
| 275 | raise ProgrammingError( |
| 276 | "Cannot open a new connection in an atomic block." |
| 277 | ) |
| 278 | with self.wrap_database_errors: |
| 279 | self.connect() |
| 280 | |
| 281 | # ##### Backend-specific wrappers for PEP-249 connection methods ##### |
| 282 |