MCPcopy
hub / github.com/psycopg/psycopg / __exit__

Method __exit__

psycopg/psycopg/connection.py:155–176  ·  view source on GitHub ↗
(
        self,
        exc_type: type[BaseException] | None,
        exc_val: BaseException | None,
        exc_tb: TracebackType | None,
    )

Source from the content-addressed store, hash-verified

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:

Callers

nothing calls this directly

Calls 3

rollbackMethod · 0.95
commitMethod · 0.95
closeMethod · 0.95

Tested by

no test coverage detected