Opened 5 years ago

Closed 5 years ago

Last modified 5 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 Changed 5 years ago by Aymeric Augustin

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 Changed 5 years ago by Richard Eames

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 Changed 5 years ago by Aymeric Augustin

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

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

comment:4 Changed 5 years ago by Richard Eames

Triage Stage: AcceptedUnreviewed

comment:5 Changed 5 years ago by Aymeric Augustin

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 Changed 5 years ago by Richard Eames

Cc: django@… added

Done, and flake8 passes on both changed files.

comment:7 Changed 5 years ago by Richard Eames <reames@…>

Resolution: fixed
Status: assignedclosed

In 7beaeeed2b99ec120486ee53e1eb7f1fe2515b9c:

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

comment:8 Changed 5 years ago by Aymeric Augustin <aymeric.augustin@…>

In 26cd19561331ac4a8a5f084a30c8ba0123d33278:

Merge pull request #2804 from AsymmetricVentures/issue22814

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

comment:9 Changed 5 years ago by anonymous

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

comment:10 Changed 5 years ago by Aymeric Augustin

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 Changed 5 years ago by Aymeric Augustin <aymeric.augustin@…>

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