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).
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).