Opened 8 years ago

Closed 2 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

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 Changed 8 years ago by empty

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 8 years ago by ubernostrum

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 7 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 7 years ago by jacob

  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:6 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:7 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:8 Changed 2 years ago by claudep

  • Resolution set to fixed
  • Status changed from new to closed

This seems to be solved since that time.

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