Bug #97953 fetchmany (in python connector) never empties if there is a remainder

Submitted: 10 Dec 2019 18:55 Modified: 12 Dec 2019 5:05
Reporter: Danielle Gardner Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:8.0.18 OS:Any
Assigned to: CPU Architecture:Any

[10 Dec 2019 18:55] Danielle Gardner
Description:
In mysql-connector-python, the cursor.fetchmany(size=N) method is supposed to fetch the next N rows of a query result set. When none are available, it should return an empty list. However, it only appears to work is intended when the size of the result set M is divisible by N. Otherwise, the method will return the first row of the last valid response indefinitely. This is unintended behavior, and may have consequences for code assuming an empty output once the method has fetches all rows of the response.

How to repeat:
In python, via the mysql connector, connect to a test database. Create a table "example_table" with a single column "id" and 8 rows with values 1 through 8.

Run `cursor.execute('SELECT * FROM example_table') `.
Next run cursor.fetchmany(4) three times. The responses will be [(1,), (2,), (3,), (4,)], then [(5,), (6,), (7,), (8,)], then []. If you keep running it, you will keep getting the empty list. This is the intended behavior.

Re-run `cursor.execute('SELECT * FROM example_table') `.
Next run cursor.fetchmany(3) four times. The responses will be [(1,), (2,), (3,)], then [(4,), (5,), (6,)], then [(7,), (8,)]. On the fourth response, we would expect an empty list. Instead we get [(7,)] as the response indefinitely.

We see it works when M (8) is divisible by N (4), but not when it is not divisible by N (3).
[11 Dec 2019 12:18] MySQL Verification Team
Hello Danielle,

Thank you for the report.
Verified as described.

regards,
Umesh
[12 Dec 2019 5:05] MySQL Verification Team
It turned out internally that it is duplicate of Bug #97830.
Marking this as duplicate of Bug #97830.

regards,
Umesh

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.053 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.