Opened 7 years ago

Closed 7 years ago

#28076 closed Cleanup/optimization (fixed)

parse_duration() doesn't work with PostgreSQL's format

Reported by: Matthew Schinckel Owned by: Matthew Schinckel
Component: Utilities Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have noticed that when creating JSON data in postgres (that includes an INTERVAL column), and then attempting to use a DurationField to re-inflate that data results in a validation error.

It seems that parse_duration only handles a very limited set of formats (ISO8601, and '1 days, 04:00:00'), however, postgres's format is slightly different.

'1 day 04:00:00'

I think this format could quite easily be handled by that function.

Any opposition to a patch that does that?

Change History (8)

comment:1 by Matthew Schinckel, 7 years ago

Owner: changed from me to Matthew Schinckel

comment:2 by Matthew Schinckel, 7 years ago

Easy pickings: set
Has patch: set
Needs tests: set

comment:3 by Matthew Schinckel, 7 years ago

Turned out to be easier than I thought: It's just making the comma optional.

comment:4 by Matthew Schinckel, 7 years ago

Hmm. Not quite.

There's some other differences: it's legal to have '-1 day, +04:00:00', for instance, which the standard_duration_re will not match.

comment:5 by Tim Graham, 7 years ago

Component: FormsUtilities
Easy pickings: unset
Summary: DurationField does not work with postgres's default format when dumping to JSON.parse_duration() doesn't work with PostgreSQL's format
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

You may want to also look at #25060 which suggests some changes to parse_duration().

comment:6 by Matthew Schinckel, 7 years ago

Thanks Tim.

It looks to me that str(timedelta) is a subset of the format used by Postgres.

comment:7 by Matthew Schinckel, 7 years ago

Oh wait, I read that wrong. It looks to me that parse_duration _already_ does parse str(timedelta)...

comment:8 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In 493f7e9e:

Fixed #28076 -- Added support for PostgreSQL's interval format to parse_duration().

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