Bug #95355 mysql-connector-python returns False as None
Submitted: 13 May 2019 12:48 Modified: 3 May 2022 18:15
Reporter: j p Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version:8.0.16 OS:Ubuntu (Ubuntu 18 LTS)
Assigned to: CPU Architecture:x86

[13 May 2019 12:48] j p
Description:
This bug prevents the standard Django Auth module from changig a user's password by triggering the error 'is_superuser cannot be NULL'

At first reported and described in detail here:
https://code.djangoproject.com/ticket/30469

Python Version: 3.7.3
mysql-connector-python Version: 8.0.16

The database is created using the following Migration code:

('is_superuser', models.BooleanField(
 default=False,
 # ... 
)),

A direct SELECT query for a False value returns NULL as well:

Please refer to the ticket linked above for details, isolated test case below

How to repeat:
#!/usr/bin/env python
"""
  Minimal test case for bug mysql-connector-python returns False as None.
  Run this in the Django propject root.
"""
import os
import mysql.connector.django

mydb = mysql.connector.connect(
    host=os.environ['DB_SERVICE'],
    user="root",
    passwd=os.environ['MYSQL_ROOT_PASSWORD']
)

mycursor = mydb.cursor()
print(mycursor.execute("SELECT %s", [False]))

This should print False but actually prints None.

Suggested fix:
Makes sure the correct value boolean False is returned instead of None if the database field is set to False and not NULL
[13 May 2019 12:52] j p
Sorry, test script is not correct.

To reproduce error you should install a minimal django start project with the database configuration as specified and try to change a user's password to trigger the error.
[12 Jun 2019 8:03] MySQL Verification Team
Hello!

Thank you for the report.

regards,
Umesh
[3 May 2022 18:15] Javier TreviƱo
The cursor.execute() executes the statement and doesn't return a value. To
fetch the result using cursors, the cursor.fetchone() or cursor.fetchall()
should be called instead.