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 , 17 years ago
comment:2 by , 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 , 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 , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:8 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This seems to be solved since that time.
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.