Unable to serialize UUIDField when running dumpdata with JSON format
A model using a UUIDField as its primary key. Running dumpdata management command with JSON output format (the default option) resulted in the following error
CommandError: Unable to serialize database: UUID('435697b4-954a-4b9a-a83a-2b53016b0d43') is not JSON serializable
However running again with --format=xml did not result in an error and dumpdata was successful.
Change History
(17)
| Description: |
modified (diff)
|
| Summary: |
Unable to serialize UUID field when running dumpdata with JSON format → Unable to serialize UUIDField when running dumpdata with JSON format
|
| Component: |
Utilities → Core (Serialization)
|
| Severity: |
Normal → Release blocker
|
| Triage Stage: |
Unreviewed → Accepted
|
| Resolution: |
→ needsinfo
|
| Status: |
new → closed
|
| Resolution: |
needsinfo
|
| Status: |
closed → new
|
| Owner: |
changed from nobody to Andriy Sokolovskiy
|
| Status: |
new → assigned
|
| Cc: |
me@… added
|
| Has patch: |
set
|
| Resolution: |
→ fixed
|
| Status: |
assigned → closed
|
I created a custom user with UUID pk:
import uuid from django.contrib.auth.models import AbstractUser from django.db import models class UUIDUser(AbstractUser): id = models.UUIDField(primary_key=True, default=uuid.uuid4)And then tried:
python manage.py dumpdata uuiduser.UUIDUser [{"fields": {"username": "tim", "first_name": "", "last_name": "", "is_active": true, "is_superuser": true, "is_staff": true, "last_login": "2015-02-11T19:01:02.747Z", "groups": [], "user_permissions": [], "password": "...", "email": "a@g.com", "date_joined": "2015-02-11T18:55:33.572Z"}, "model": "uuiduser.uuiduser", "pk": "dd100fcd-a894-4435-ad30-bdcd4671ac44"}]Tested on SQLite and PostgreSQL. Could you provide more details? I'm also attached a test for Django's test suite that I tried writing to reproduce the issue.