Opened 5 years ago

Closed 5 years ago

#25019 closed Bug (fixed)

DjangoJSONEncoder does not encode UUIDs

Reported by: lukas-hetzenecker Owned by: nobody
Component: Core (Serialization) Version: 1.8
Severity: Normal Keywords: UUIDField DjangoJSONEncoder
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by James Rivett-Carnac)

Django extends the standard the json encoder from the standard library to enhance its functionality, for example by providing methods to serialize Datetimes and Decimals.

Because UUIDField was included in Django, serialization of uuid.UUID should be possible too.
There are projects out there that make use of UUIDFields and that will run in problems if they try to serialize the model. An example for such a bug report is https://github.com/sehmaschine/django-grappelli/issues/635

Example project is attached.

EDIT

Reopened as Bug with version 1.8 in response to conversation with Russell Keith-Magee in django-developers mailing list.

Attachments (1)

example.tar.gz (2.7 KB) - added by lukas-hetzenecker 5 years ago.

Download all attachments as: .zip

Change History (9)

Changed 5 years ago by lukas-hetzenecker

Attachment: example.tar.gz added

comment:1 Changed 5 years ago by lukas-hetzenecker

Easy pickings: set

comment:2 Changed 5 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted

comment:3 Changed 5 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In 6355a6d:

Fixed #25019 -- Added UUID support in DjangoJSONEncoder

comment:4 Changed 5 years ago by James Rivett-Carnac

This also impacts the use of UUID fields in other projects, such as django-allauth,

https://github.com/pennersr/django-allauth/issues/916

I believe this fix should also be back ported to the 1.8.x branch because the expected behaviour of 'I serialise my User Model which has a UUID field' into my session or cache crashes.

Cherry picking this commit into the 1.8.x branch fixed all my problems.

comment:5 Changed 5 years ago by James Rivett-Carnac

Description: modified (diff)
Resolution: fixed
Status: closednew
Type: New featureBug
Version: master1.8

comment:6 Changed 5 years ago by James Rivett-Carnac

comment:7 Changed 5 years ago by Claude Paroz <claude@…>

In 2e05ef4e:

Added release note for the UUID serialization backport

Refs #25019.

comment:8 Changed 5 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In ebcfedb0:

[1.8.x] Fixed #25019 -- Added UUID support in DjangoJSONEncoder

Backport of 6355a6d4f5 and 2e05ef4e18 from master.

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