Opened 4 years ago

Closed 3 years ago

#26656 closed New feature (fixed)

Add timedelta support to DjangoJSONEncoder

Reported by: Will Hardy Owned by: nobody
Component: Core (Serialization) Version: 1.9
Severity: Normal Keywords:
Cc: Chesco Igual Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently DjangoJSONEncoder supports datetime, date, time, Decimal and UUID objects.

But when the DurationField was added recently, no support for timedelta was added to the JSON encoder.

Change History (10)

comment:1 Changed 4 years ago by Tim Graham

Component: UncategorizedCore (Serialization)
Type: UncategorizedNew feature

comment:2 Changed 4 years ago by Will Hardy

See another PR, using a ISO 8601 string instead of a float.

comment:3 Changed 4 years ago by Tim Graham

Has patch: set
Triage Stage: UnreviewedAccepted

comment:4 Changed 4 years ago by Chesco Igual

Cc: Chesco Igual added
Triage Stage: AcceptedReady for checkin

I gave a look at the code, and seems to solve the problem. Adds support for ISO durations. Includes new tests which seem to cover most of the cases (replicates previous duration tests, with the new ISO format).

Only thing is I am not able to tell if the format should be included anywhere in the official docs of the serializers or if it's not necessary.

comment:5 Changed 4 years ago by Tom Offermann

Looks good! Reviewed as part of the Django sprint at PyCon.

tests.serializers.test_json:test_timedelta passes with the patch. It fails without the patch.

The new TestParseISODurationRoundtrip tests look good.

Does this need docs?

comment:6 Changed 4 years ago by Will Hardy

DjangoJSONEncoder does not seem to be documented at all. I've added an entry to the release notes, and will open another ticket for the whole class to be documented.

comment:7 Changed 4 years ago by Will Hardy

See #26704 for the DjangoJSONEncoder documentation ticket.

Last edited 4 years ago by Tim Graham (previous) (diff)

comment:8 Changed 4 years ago by Tim Graham

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

Now that #26704 is committed, we can update those docs for these changes.

comment:9 Changed 4 years ago by Tim Graham

Patch needs improvement: unset

comment:10 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 8ef78b8:

Fixed #26656 -- Added duration (timedelta) support to DjangoJSONEncoder.

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