From: Daniele Varrazzo Date: Wed, 25 Oct 2023 18:23:08 +0000 (+0200) Subject: refactor: move setting autocommit on connection out of _connect_gen X-Git-Tag: 3.1.13~2^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e61d7fe09a9a21b42260c10e01f0179c2dbc156;p=thirdparty%2Fpsycopg.git refactor: move setting autocommit on connection out of _connect_gen --- diff --git a/psycopg/psycopg/connection.py b/psycopg/psycopg/connection.py index ca9305394..5f3437321 100644 --- a/psycopg/psycopg/connection.py +++ b/psycopg/psycopg/connection.py @@ -432,13 +432,10 @@ class BaseConnection(Generic[Row]): def _connect_gen( cls: Type[ConnectionType], conninfo: str = "", - *, - autocommit: bool = False, ) -> PQGenConn[ConnectionType]: """Generator to connect to the database and create a new instance.""" pgconn = yield from connect(conninfo) conn = cls(pgconn) - conn._autocommit = bool(autocommit) return conn def _exec_command( @@ -731,12 +728,12 @@ class Connection(BaseConnection[Row]): try: rv = cls._wait_conn( - cls._connect_gen(conninfo, autocommit=autocommit), - timeout=params["connect_timeout"], + cls._connect_gen(conninfo), timeout=params["connect_timeout"] ) except e._NO_TRACEBACK as ex: raise ex.with_traceback(None) + rv._autocommit = bool(autocommit) if row_factory: rv.row_factory = row_factory if cursor_factory: diff --git a/psycopg/psycopg/connection_async.py b/psycopg/psycopg/connection_async.py index 416d00cee..5ab0522b0 100644 --- a/psycopg/psycopg/connection_async.py +++ b/psycopg/psycopg/connection_async.py @@ -122,12 +122,12 @@ class AsyncConnection(BaseConnection[Row]): try: rv = await cls._wait_conn( - cls._connect_gen(conninfo, autocommit=autocommit), - timeout=params["connect_timeout"], + cls._connect_gen(conninfo), timeout=params["connect_timeout"] ) except e._NO_TRACEBACK as ex: raise ex.with_traceback(None) + rv._autocommit = bool(autocommit) if row_factory: rv.row_factory = row_factory if cursor_factory: