Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit c41d881

Browse files
Run postgres iterate within a transaction
1 parent 788700f commit c41d881

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

databases/backends/postgres.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ async def iterate(
169169
self, query: ClauseElement
170170
) -> typing.AsyncGenerator[typing.Any, None]:
171171
assert self._connection is not None, "Connection is not acquired"
172-
query, args, result_columns = self._compile(query)
173-
async for row in self._connection.cursor(query, *args):
174-
yield Record(row, result_columns, self._dialect)
172+
async with self.transaction():
173+
query, args, result_columns = self._compile(query)
174+
async for row in self._connection.cursor(query, *args):
175+
yield Record(row, result_columns, self._dialect)
175176

176177
def transaction(self) -> TransactionBackend:
177178
return PostgresTransaction(connection=self)

0 commit comments

Comments
 (0)