Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#22814 closed Bug (fixed)

parse_datetime can't parse datetimes returned from postgresql

Reported by: Richard Eames Owned by: Aymeric Augustin
Component: Utilities Version: 1.6
Severity: Normal Keywords:
Cc: django@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The datetime format returned by postgresql is "2014-06-11 23:31:38.134266+00" which is failed to parsed because the offset is only two digits.

Change History (11)

comment:1 by Aymeric Augustin, 10 years ago

Where does Django call parse_datetime on a value returned by PostgreSQL?

If it never does, I'd just document the expected format.

comment:2 by Richard Eames, 10 years ago

django.db.models.fields.DateTimeField calls it in its to_python method. I recommend django switch to be closer to ISO-8601 which allows the following formats: Z; [+-]hh:mm, [+-]hhmm, [+-]hh
Currently parse_datetime allows all except the last case which was taken out in 2f59e94a4150c84c8b4 because it (mistakenly) also allowed [+-]hm

I propose that [+-]hh be reintroduced with the semantics outlined in ISO-8601. (I'll create a PR)

comment:3 by Aymeric Augustin, 10 years ago

Owner: changed from nobody to Aymeric Augustin
Status: newassigned
Triage Stage: UnreviewedAccepted

Wikipedia confirms that ±hh is supported. Let's do this.

comment:4 by Richard Eames, 10 years ago

Triage Stage: AcceptedUnreviewed

comment:5 by Aymeric Augustin, 10 years ago

Has patch: set
Triage Stage: UnreviewedReady for checkin

Looks good. My only comment is the most insignificant I ever left on a PR :-) If you can amend the commit and force-push it, I'll merge it.

comment:6 by Richard Eames, 10 years ago

Cc: django@… added

Done, and flake8 passes on both changed files.

comment:7 by Richard Eames <reames@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 7beaeeed2b99ec120486ee53e1eb7f1fe2515b9c:

Fixed #22814 -- Allowed ISO-8601 [+-]hh timezone format in parse_datetime

comment:8 by Aymeric Augustin <aymeric.augustin@…>, 10 years ago

In 26cd19561331ac4a8a5f084a30c8ba0123d33278:

Merge pull request #2804 from AsymmetricVentures/issue22814

Fixed #22814 -- Allowed ISO-8601 [+-]hh timezone format in parse_datetime

comment:9 by anonymous, 10 years ago

Any chance of getting this backported to 1.7 and/or 1.6?

comment:10 by Aymeric Augustin, 10 years ago

I'll do it for 1.7.

I'd rather not do it in 1.6. I'm wary of making small changes in low level utilities in stable versions because people tend to rely on the exact behaviour, sometimes after checking the source.

comment:11 by Aymeric Augustin <aymeric.augustin@…>, 10 years ago

In 8dcc7810f07e2ce76ebee50c70a5c16f1bc9edec:

[1.7.x] Fixed #22814 -- Allowed ISO-8601 [+-]hh timezone format in parse_datetime

Backport of 7beaeeed from master.

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