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

Commit 9620be9

Browse files
Fix postgres transactions around iteration
1 parent 807b983 commit 9620be9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

databases/backends/postgres.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,16 @@ 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-
async with self.transaction():
172+
transaction = PostgresTransaction(self)
173+
await transaction.start()
174+
try:
173175
query, args, result_columns = self._compile(query)
174176
async for row in self._connection.cursor(query, *args):
175177
yield Record(row, result_columns, self._dialect)
178+
except:
179+
transaction.rollback()
180+
else:
181+
transaction.commit()
176182

177183
def transaction(self) -> TransactionBackend:
178184
return PostgresTransaction(connection=self)

0 commit comments

Comments
 (0)