Opened 11 years ago

Closed 5 years ago

#6276 closed Bug (fixed)

Serializers should dump correct data for BooleanFields

Reported by: anonymous Owned by: nobody
Component: Core (Other) Version: master
Severity: Normal Keywords: serializer booleanfield
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I recently transferred my app from Mysql to Postgres and found out that dumping the db using dumpdata on the Mysql-database returned in values like "is_superuser" : 1 for json. This is fine from a Mysql point of view, but bad for Postgres. Why? Well the Postgres backend uses a Boolen Field Type for Django's BooleanField whereas Mysql uses a TinyInt(?) with length 1. So I wasn't able to load the data in Postgres as it complained about wrong types (expecting boolean, got integer, or something like this...). It worked fine after converting 1 to "True" and 0 to "False"-

Change History (8)

comment:1 Changed 10 years ago by empty

The light switch can only be on or off. How do you propose it gets dumped? It can only be dumped in a way that's consistent with the database that is doing the dumping.

comment:2 Changed 10 years ago by James Bennett

I ran into this myself once; IIRC it's only a problem in the JSON serializer, and only on deserialization; the XML serializer handles this fine, but the JSON one doesn't cast back from int to bool.

comment:3 Changed 10 years ago by Eric B <ebartels@…>

I've just run into this problem as well. It happens for yaml and xml formats as well. The problem is that Postgres dumps booleans as true/false and expects that format back with loaddata, otherwise it gives an error. Mysql dumps booleans as integers, but (at least version 5.0) is fine with inserting true/false as well.

comment:4 Changed 10 years ago by Jacob

Triage Stage: UnreviewedAccepted

comment:5 Changed 7 years ago by Julien Phalip

Severity: Normal
Type: Bug

comment:6 Changed 6 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:7 Changed 6 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:8 Changed 5 years ago by Claude Paroz

Resolution: fixed
Status: newclosed

This seems to be solved since that time.

Note: See TracTickets for help on using tickets.
Back to Top