| 153 | return self |
| 154 | |
| 155 | def __exit__( |
| 156 | self, |
| 157 | exc_type: type[BaseException] | None, |
| 158 | exc_val: BaseException | None, |
| 159 | exc_tb: TracebackType | None, |
| 160 | ) -> None: |
| 161 | if self.closed: |
| 162 | return |
| 163 | |
| 164 | if exc_type: |
| 165 | # try to rollback, but if there are problems (connection in a bad |
| 166 | # state) just warn without clobbering the exception bubbling up. |
| 167 | try: |
| 168 | self.rollback() |
| 169 | except Exception as exc2: |
| 170 | logger.warning("error ignored in rollback on %s: %s", self, exc2) |
| 171 | else: |
| 172 | self.commit() |
| 173 | |
| 174 | # Close the connection only if it doesn't belong to a pool. |
| 175 | if not getattr(self, "_pool", None): |
| 176 | self.close() |
| 177 | |
| 178 | @classmethod |
| 179 | def _get_connection_params(cls, conninfo: str, **kwargs: Any) -> ConnDict: |