From: Daniele Varrazzo Date: Mon, 23 Nov 2020 15:11:44 +0000 (+0000) Subject: Fixed tiny diffreences in behaviour between sync and async code X-Git-Tag: 3.0.dev0~320 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8dffb74d6348e0377b33bdef3221b61f8da75e03;p=thirdparty%2Fpsycopg.git Fixed tiny diffreences in behaviour between sync and async code --- diff --git a/psycopg3/psycopg3/connection.py b/psycopg3/psycopg3/connection.py index df6f264ca..2d822fb73 100644 --- a/psycopg3/psycopg3/connection.py +++ b/psycopg3/psycopg3/connection.py @@ -328,7 +328,6 @@ class Connection(BaseConnection): elif isinstance(command, Composable): command = command.as_string(self).encode(self.client_encoding) - logger.debug(f"{self}: {command!r}") self.pgconn.send_query(command) results = self.wait(execute(self.pgconn)) if results[-1].status != ExecStatus.COMMAND_OK: @@ -455,26 +454,26 @@ class AsyncConnection(BaseConnection): async def commit(self) -> None: async with self.lock: - if self.pgconn.transaction_status == TransactionStatus.IDLE: - return if self._savepoints: raise e.ProgrammingError( "Explicit commit() forbidden within a Transaction " "context. (Transaction will be automatically committed " "on successful exit from context.)" ) + if self.pgconn.transaction_status == TransactionStatus.IDLE: + return await self._exec_command(b"commit") async def rollback(self) -> None: async with self.lock: - if self.pgconn.transaction_status == TransactionStatus.IDLE: - return if self._savepoints: raise e.ProgrammingError( "Explicit rollback() forbidden within a Transaction " "context. (Either raise Rollback() or allow " "an exception to propagate out of the context.)" ) + if self.pgconn.transaction_status == TransactionStatus.IDLE: + return await self._exec_command(b"rollback") async def _exec_command(self, command: Query) -> None: @@ -521,7 +520,7 @@ class AsyncConnection(BaseConnection): async with self.lock: self.pgconn.send_query_params( b"select set_config('client_encoding', $1, false)", - [name.encode("utf-8")], + [encodings.py2pg(name)], ) gen = execute(self.pgconn) (result,) = await self.wait(gen) diff --git a/psycopg3/psycopg3/cursor.py b/psycopg3/psycopg3/cursor.py index 8cf5b6887..c35d71d14 100644 --- a/psycopg3/psycopg3/cursor.py +++ b/psycopg3/psycopg3/cursor.py @@ -485,9 +485,9 @@ class Cursor(BaseCursor["Connection"]): if not size: size = self.arraysize - rv: List[Sequence[Any]] = [] pos = self._pos load = self._transformer.load_row + rv: List[Sequence[Any]] = [] for _ in range(size): row = load(pos) @@ -610,7 +610,7 @@ class AsyncCursor(BaseCursor["AsyncConnection"]): load = self._transformer.load_row rv: List[Sequence[Any]] = [] - for i in range(size): + for _ in range(size): row = load(pos) if row is None: break