Opened 17 years ago

Closed 12 years ago

#6276 closed Bug (fixed)

Serializers should dump correct data for BooleanFields

Reported by: anonymous Owned by: nobody
Component: Core (Other) Version: dev
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

Description

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 by empty, 17 years ago

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 by James Bennett, 17 years ago

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 by Eric B <ebartels@…>, 17 years ago

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 by Jacob, 16 years ago

Triage Stage: UnreviewedAccepted

comment:5 by Julien Phalip, 14 years ago

Severity: Normal
Type: Bug

comment:6 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:7 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:8 by Claude Paroz, 12 years ago

Resolution: fixed
Status: newclosed

This seems to be solved since that time.

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