Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23216 closed Bug (worksforme)

CheckboxInput does not work properly with value "0"

Reported by: maciej.pawlisz@… Owned by: nobody
Component: Forms Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I loaded data to my local sqlite database from mysql database using modified mysqldump script. All boolean fields are now stored with "0" and "1" instead of "True" and "False" - sqlite datatype is tinyint instead of bool, which is not present in mysql.
Now checkboxes are always checked because of this function which does not work with 0 and 1

django.forms.widgets.py:457
def boolean_check(v):
    return not (v is False or v is None or v == '')

Also BooleanField.to_python() method is not called (which would properly convert this value to Boolean), only Field.prepare_value which does nothing

Because of this bug all users seem to be superusers in django admin.

Attachments (2)

tinyint_superuser1.png (12.8 KB ) - added by maciej.pawlisz@… 10 years ago.
SQL Select from Django debug toolbar
tinyint_superuser2.png (19.2 KB ) - added by maciej.pawlisz@… 10 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 by Tim Graham, 10 years ago

Resolution: worksforme
Status: newclosed

I see values of 0 and 1 in the auth_user table of my SQLite database and there is no problem so I suspect the bug is not in Django.

comment:2 by maciej.pawlisz@…, 10 years ago

It works ok when is_superuser column has type bool. After my import it has type tinyint(1) and is not working. Both column types are visible as 0 and 1 in SQLite Manager. I suspect that SQLite driver in python is making automatic conversion to True and False for bool column type.
I understand that tinyint(1) is not a typical column type for BooleanField and that is the cause of this problem. I will attach screenshots that visualize this situation (is_superuser column has type changed to tinyint(1) by SQLite Manager)

by maciej.pawlisz@…, 10 years ago

Attachment: tinyint_superuser1.png added

SQL Select from Django debug toolbar

by maciej.pawlisz@…, 10 years ago

Attachment: tinyint_superuser2.png added
Note: See TracTickets for help on using tickets.
Back to Top