Skip to content

Commit f87125f

Browse files
author
James William Pye
committed
Choose the minimum quantity when quantity is not None.
This was causing oversized reads to occur due to the slice being decided by the new buffer's size. When quantity is None, we read them all, so end_of_block is based on the buffer size.
1 parent dab381e commit f87125f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

postgresql/driver/pq3.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108

109109
TransactionIsPrepared = """
110110
SELECT TRUE FROM pg_catalog.pg_prepared_xacts
111-
WHERE gid::text = $1;
111+
WHERE gid::text = $1
112112
"""
113113

114114
GetPreparedStatement = """
@@ -466,8 +466,11 @@ def read(self, quantity = None):
466466
left_to_read -= expanded
467467
##
468468
# The real quantity becomes the difference
469-
# in the buffer length[len(1)] and the offset(0).
470-
quantity = len(self._state[1]) - offset
469+
# in the buffer length[len(1)] and the offset(0) or
470+
# remains the request if more than quantity is buffered.
471+
quantity = len(self._state[1]) - offset \
472+
if quantity is None \
473+
else min(len(self._state[1]) - offset, quantity)
471474

472475
end_of_block = offset + quantity
473476
t = self._state[1][offset:end_of_block]

0 commit comments

Comments
 (0)