Bug #110856 The python mysql.connector cursor etchmany method returns error
Submitted: 28 Apr 2023 3:00 Modified: 8 May 2023 10:58
Reporter: jie li Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S1 (Critical)
Version:8.0.31 OS:Any
Assigned to: CPU Architecture:Any

[28 Apr 2023 3:00] jie li
Description:
The python mysql.connector cursor etchmany method returns error

Returns a duplicate value in the case of multiple calls

How to repeat:

import mysql.connector
test_conn = mysql.connector.connect(user='root',host='127.0.0.1',database='test_data')
cur =  test_conn.cursor()
cur.execute('select * from test_data')

# The following two calls return the same data
cur.fetchmany()
cur.fetchmany()

Suggested fix:
https://peps.python.org/pep-0249/#:~:text=%E5%AD%90%E7%B1%BB%EF%BC%89%E5%BC%82%E5%B8%B8%E3...
[28 Apr 2023 8:33] MySQL Verification Team
Hello jie li,

Thank you for the report and feedback.

regards,
Umesh
[28 Apr 2023 12:05] MySQL Verification Team
Could you please provide exact test case to reproduce the issue? I thought, was able to repro but had typo and lead has corrected me and I can confirm that in Conn/Python 8.0.33 it works as expected:

-- using Sakila schema 

import mysql.connector
import sys
import platform

print("OS: {} {}".format(platform.system(), platform.release()))
print("Python:", format(sys.version))
driver  = mysql.connector
print("Driver: {} {}".format(driver.__name__, driver.__version__))

test_conn = mysql.connector.connect(user='root',password='mysql123', host='127.0.0.1',database='sakila')
cur =  test_conn.cursor()
cur.execute('select * from sakila.actor')

# The following two calls return the same data
records = cur.fetchmany()
print("Fetching Total ", len(records), " rows")
print("Printing each row")
for row in records:
    print("Actor Id: ", row[0])
    print("First Name: ", row[1])
    print("Last Name: ", row[2])
    print("Last update: ", row[3])
    print("\n")

records1 = cur.fetchmany()
print("Fetching Total ", len(records1), " rows")
print("Printing each row")
for row1 in records1:
    print("Actor Id: ", row1[0])
    print("First Name: ", row1[1])
    print("Last Name: ", row1[2])
    print("Last update: ", row1[3])
    print("\n")

--

OS: Windows 10
Python: 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]
Driver: mysql.connector 8.0.33
Fetching Total  1  rows
Printing each row
Actor Id:  1
First Name:  PENELOPE
Last Name:  GUINESS
Last update:  2006-02-15 04:34:33

Fetching Total  1  rows
Printing each row
Actor Id:  2
First Name:  NICK
Last Name:  WAHLBERG
Last update:  2006-02-15 04:34:33

Press any key to continue . . .
[28 Apr 2023 12:17] MySQL Verification Team
- C/Python

OS: Windows 10
Python: 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]
Driver: mysql.connector 8.0.31
Fetching Total  1  rows
Printing each row
Actor Id:  1
First Name:  PENELOPE
Last Name:  GUINESS
Last update:  2006-02-15 04:34:33

Fetching Total  1  rows
Printing each row
Actor Id:  2
First Name:  NICK
Last Name:  WAHLBERG
Last update:  2006-02-15 04:34:33

Press any key to continue . . .
[8 May 2023 10:53] jie li
Sorry, this is my test code

OS: Darwin 22.4.0
Python: 3.9.12 (main, Apr  5 2022, 01:52:34)
[Clang 12.0.0 ]
Driver: mysql.connector 8.0.31

import mysql.connector
test_conn = mysql.connector.connect(user='root',host='127.0.0.1',database='test_data')
cur =  test_conn.cursor()
cur.execute('select * from tb_data')

# The following two calls return the same data
print(cur.fetchmany())
print(cur.fetchmany())

I upgraded to 8.0.33 This issue has been fixed

OS: Darwin 22.4.0
Python: 3.9.12 (main, Apr  5 2022, 01:52:34)
[Clang 12.0.0 ]
Driver: mysql.connector 8.0.33
[8 May 2023 10:58] MySQL Verification Team
Thank you for confirming that you no longer see the issue with Con/Python 8.0.33. Closing the report for now.Thank you.

regards,
Umesh