The bug was updated successfully. The following people were notified: the MySQL developers, the bug reporter, the assigned lead, interested observers, and nobody else.
Bug #108145 | MySQLCursor.executemany() fails to correctly identify BULK data loading ops | ||
---|---|---|---|
Submitted: | 16 Aug 2022 8:13 | Modified: | 21 Oct 2022 20:45 |
Reporter: | Alex Cazacu (OCA) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / Python | Severity: | S2 (Serious) |
Version: | 8.0.30 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[16 Aug 2022 8:13]
Alex Cazacu
[16 Aug 2022 12:54]
MySQL Verification Team
Hello Alex Cazacu, Thank you for the report and feedback. With the provided test case on VS 2022, Python 3.10 and Connector/Python 8.0.30: File "C:\Work\Connectors\Python\Bug108145\Bug108145\Bug108145.py", line 13 cursor.executemany("INSERT INTO 'test_database'.'test_table'" ('test_field') VALUES('%s'), [['test_field_1'], ['test_field_2'], ['test_field_3']]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: invalid syntax. Perhaps you forgot a comma? Press any key to continue . . . -- With changes cursor.executemany("INSERT INTO test_database.test_table (test_field) VALUES(%s)", [['test_field_1'], ['test_field_2'], ['test_field_3']]) I can confirm the reported issue : 2022-08-16T12:52:52.826605Z 20 Query set autocommit=0 2022-08-16T12:52:52.827215Z 20 Query INSERT INTO test_database.test_table (test_field) VALUES('test_field_1') 2022-08-16T12:52:52.839012Z 20 Query INSERT INTO test_database.test_table (test_field) VALUES('test_field_2') 2022-08-16T12:52:52.839577Z 20 Query INSERT INTO test_database.test_table (test_field) VALUES('test_field_3') 2022-08-16T12:52:52.839948Z 20 Query commit This seems to be a regression as I didn't see this with C/Python 8.0.29. regards, Umesh
[16 Aug 2022 13:40]
Alex Cazacu
Hi Umesh, Thank you for picking this up! To provide some more context on the root cause, this is the git blame for the file containing the RE sentinel for executemany BULK data loading operations: https://github.com/mysql/mysql-connector-python/blame/master/lib/mysql/connector/cursor.py You can see that the commit that last modified the RE sentinel was: https://github.com/mysql/mysql-connector-python/commit/ddf6b13704e0e409bb8cac292acc4292850... Analyzing the previous of the code, you can see that format was invoked on the r statement. Due to this invocation, the {x,y} quantifier in the RE had to be escaped by adding additional, surrounding curly braces: {{x,y}}. Since the string containing the quantifier is no longer being formatted (the .format invocation was removed), escaping of the RE quantifier is no longer performed and the additional curly braces are seeping into the RE statement itself, making it invalid for its intended purpose. Removing the wrapping curly braces of the RE quantifier on line https://github.com/mysql/mysql-connector-python/blob/master/lib/mysql/connector/cursor.py#... should fix the reported issue and resolve the regression.
[16 Aug 2022 14:00]
Alex Cazacu
Maybe this is more efficient, I have created a PR to resolve the issue: https://github.com/mysql/mysql-connector-python/pull/81 Thank you! Best, Alex
[13 Oct 2022 18:03]
Oscar Pacheco
Posted by developer: Thanks, Alex Cazacu for the contribution. Your patch (http://github.com/mysql/mysql-connector-python/pull/81) has been reviewed and integrated into the internal main branch. Regards.
[21 Oct 2022 20:45]
Philip Olson
Posted by developer: Fixed as of the upcoming MySQL Connector/Python 8.0.32 release, and here's the proposed changelog entry from the documentation team: The MySQLCursor.executemany() method failed to batch insert data since the regular expression (RE) sentinel did not detect batch cases correctly; this meant using the one-on-one insert instead, which led to decreased performance. Thanks to Alex Cazacu for the contribution. Thank you for the bug report.