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.2.0~133^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf8f433ba7b3994b36514ed1d44001bab3a38710;p=thirdparty%2Fpsycopg.git refactor: move setting autocommit on connection out of _connect_gen --- diff --git a/psycopg/psycopg/_connection_base.py b/psycopg/psycopg/_connection_base.py index fb8db5d91..cf391998b 100644 --- a/psycopg/psycopg/_connection_base.py +++ b/psycopg/psycopg/_connection_base.py @@ -423,13 +423,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 generators.connect(conninfo) conn = cls(pgconn) - conn._autocommit = bool(autocommit) return conn def _exec_command( diff --git a/psycopg/psycopg/connection.py b/psycopg/psycopg/connection.py index a5adf2a92..7d2418d81 100644 --- a/psycopg/psycopg/connection.py +++ b/psycopg/psycopg/connection.py @@ -123,12 +123,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 862a1ebe0..868c22ee7 100644 --- a/psycopg/psycopg/connection_async.py +++ b/psycopg/psycopg/connection_async.py @@ -139,12 +139,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: