Bug #85779 mysql.connector.django.operations::bulk_insert_sql error for a single entry
Submitted: 4 Apr 2017 11:44 Modified: 4 Apr 2017 13:39
Reporter: YONGGEUN SONG Email Updates:
Status: Duplicate Impact on me:
Category:Connector / Python Severity:S2 (Serious)
Version: OS:Ubuntu
Assigned to: CPU Architecture:Any

[4 Apr 2017 11:44] YONGGEUN SONG
For whom may concern mysql connector for django backends.
I'm not sure my endpoint is whether correct or not, I couldn't find github repository at least. You had references, so please - kindly hand over this message one with the authority.

I found a tiny but destructive bug that can be somewhat critical here,
mysql.connector.django.operations, function bulk_insert_sql.

I'm using python 3.5 at the moment, however, It's pretty sure that can be repeated on several other environments.

Your code (line 223 on my side):
>> return "VALUES " + ", ".join([items_sql] * num_values) 
will fail when you have num_values=1, python2/3, either.

That is basically because tuple __str__() returns with dangling comma; as you might already know.
i.e. If you never heard of it, please try>> str(tuple('1'))

And the fact will make gradually failing django migration, admin login, and anywhere you can insert a single entry.

It's not yours, technically speaking, though I hope this bug to be avoided with simple if-else.

please refer 

How to repeat:
python 3.5
django 1.10

try to login admin interface with mysql connection.

Suggested fix:
== was ==
def bulk_insert_sql(self, fields, num_values):
  items_sql = "({0})".format(", ".join(["%s"] * len(fields)))
  return "VALUES " + ", ".join([items_sql] * num_values)

== tobe ==
def bulk_insert_sql(self, fields, num_values) :
  items_sql = "(%s)"
  if 1<len(fields) : items_sql = "({0})".format(", ".join(["%s"] * len(fields)))
  return "VALUES " + ", ".join([items_sql]*num_values) if 1<num_values else items_sql
[4 Apr 2017 13:39] Chiranjeevi Battula

Thank you for the bug report.
This duplicate of Bug #85468, Please see Bug #85468.
Issue will be fixed in the upcoming release 2.1.6.