Opened 3 years ago

Closed 2 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 Changed 3 years ago by Matthew Schinckel

Owner: changed from me to Matthew Schinckel

comment:2 Changed 3 years ago by Matthew Schinckel

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

comment:3 Changed 3 years ago by Matthew Schinckel

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

comment:4 Changed 3 years ago by Matthew Schinckel

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 Changed 3 years ago by Tim Graham

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 Changed 3 years ago by Matthew Schinckel

Thanks Tim.

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

comment:7 Changed 3 years ago by Matthew Schinckel

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

comment:8 Changed 2 years ago by Tim Graham <timograham@…>

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