[Django] #28076: DurationField does not work with postgres's default format when dumping to JSON.

61 views
Skip to first unread message

Django

unread,
Apr 12, 2017, 9:52:15 PM4/12/17
to django-...@googlegroups.com
#28076: DurationField does not work with postgres's default format when dumping to
JSON.
---------------------------------------------+--------------------------
Reporter: Matthew Schinckel | Owner: me
Type: Uncategorized | Status: assigned
Component: Forms | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+--------------------------
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?

--
Ticket URL: <https://code.djangoproject.com/ticket/28076>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 12, 2017, 9:52:35 PM4/12/17
to django-...@googlegroups.com
#28076: DurationField does not work with postgres's default format when dumping to
JSON.
-------------------------------------+-------------------------------------
Reporter: Matthew Schinckel | Owner: Matthew
| Schinckel

Type: Uncategorized | Status: assigned
Component: Forms | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Matthew Schinckel):

* owner: me => Matthew Schinckel


--
Ticket URL: <https://code.djangoproject.com/ticket/28076#comment:1>

Django

unread,
Apr 12, 2017, 10:04:33 PM4/12/17
to django-...@googlegroups.com
#28076: DurationField does not work with postgres's default format when dumping to
JSON.
-------------------------------------+-------------------------------------
Reporter: Matthew Schinckel | Owner: Matthew
| Schinckel
Type: Uncategorized | Status: assigned
Component: Forms | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0

-------------------------------------+-------------------------------------
Changes (by Matthew Schinckel):

* has_patch: 0 => 1
* needs_tests: 0 => 1
* easy: 0 => 1


Comment:

https://github.com/django/django/pull/8354

--
Ticket URL: <https://code.djangoproject.com/ticket/28076#comment:2>

Django

unread,
Apr 12, 2017, 10:05:00 PM4/12/17
to django-...@googlegroups.com
#28076: DurationField does not work with postgres's default format when dumping to
JSON.
-------------------------------------+-------------------------------------
Reporter: Matthew Schinckel | Owner: Matthew
| Schinckel
Type: Uncategorized | Status: assigned
Component: Forms | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matthew Schinckel):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/28076#comment:3>

Django

unread,
Apr 12, 2017, 10:11:27 PM4/12/17
to django-...@googlegroups.com
#28076: DurationField does not work with postgres's default format when dumping to
JSON.
-------------------------------------+-------------------------------------
Reporter: Matthew Schinckel | Owner: Matthew
| Schinckel
Type: Uncategorized | Status: assigned
Component: Forms | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28076#comment:4>

Django

unread,
Apr 15, 2017, 8:51:51 AM4/15/17
to django-...@googlegroups.com
#28076: parse_duration() doesn't work with PostgreSQL's format

-------------------------------------+-------------------------------------
Reporter: Matthew Schinckel | Owner: Matthew
Type: | Schinckel
Cleanup/optimization | Status: assigned
Component: Utilities | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => Cleanup/optimization
* component: Forms => Utilities
* easy: 1 => 0
* stage: Unreviewed => Accepted


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/28076#comment:5>

Django

unread,
Apr 19, 2017, 5:47:15 AM4/19/17
to django-...@googlegroups.com
#28076: parse_duration() doesn't work with PostgreSQL's format
-------------------------------------+-------------------------------------
Reporter: Matthew Schinckel | Owner: Matthew
Type: | Schinckel
Cleanup/optimization | Status: assigned
Component: Utilities | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matthew Schinckel):

Thanks Tim.

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

--
Ticket URL: <https://code.djangoproject.com/ticket/28076#comment:6>

Django

unread,
Apr 19, 2017, 5:48:00 AM4/19/17
to django-...@googlegroups.com
#28076: parse_duration() doesn't work with PostgreSQL's format
-------------------------------------+-------------------------------------
Reporter: Matthew Schinckel | Owner: Matthew
Type: | Schinckel
Cleanup/optimization | Status: assigned
Component: Utilities | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matthew Schinckel):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/28076#comment:7>

Django

unread,
Jul 3, 2017, 8:19:13 PM7/3/17
to django-...@googlegroups.com
#28076: parse_duration() doesn't work with PostgreSQL's format
-------------------------------------+-------------------------------------
Reporter: Matthew Schinckel | Owner: Matthew
Type: | Schinckel
Cleanup/optimization | Status: closed
Component: Utilities | Version: 1.11
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"493f7e9e1ed7d68df102de6c5926a55521b145c9" 493f7e9e]:
{{{
#!CommitTicketReference repository=""
revision="493f7e9e1ed7d68df102de6c5926a55521b145c9"
Fixed #28076 -- Added support for PostgreSQL's interval format to
parse_duration().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28076#comment:8>

Reply all
Reply to author
Forward
0 new messages