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:
And then tried:
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.