Opened 10 years ago

Closed 9 years ago

#22598 closed New feature (fixed)

make_aware throws AmbiguousTimeError exception

Reported by: trott@… Owned by: nobody
Component: Utilities Version: dev
Severity: Normal Keywords: make_aware
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When using the pytz package, the make_aware() utility function occasionally throws an AmbiguousTimeError or NonExistentTimeError exception.
As the pytz maintainer explain, some dates time values may not be localizable (using the pytz.localize() function) when the optional is_dst Parameter is

I don't think, that Django should throw an exception in these cases, that results in a "show stopper" behavior.
Instead, I would prefer to just "guess" it the is_dst parameter when these Exceptions occur. That may result in a 50% chance to get a 1 hour
miscalculation – but until we don't know a better way, I just prefer that instead of having some values not saved at all...

Anyway, I attached a little patch to prevent this nasty Exceptions.

Attachments (1)

timezone.diff (943 bytes ) - added by trott@… 10 years ago.
patch for utils/

Download all attachments as: .zip

Change History (4)

by trott@…, 10 years ago

Attachment: timezone.diff added

patch for utils/

comment:1 by Aymeric Augustin, 10 years ago

Resolution: wontfix
Status: newclosed
% python -m this | grep ambiguity
In the face of ambiguity, refuse the temptation to guess.

comment:2 by Josh Smeaton, 9 years ago

Resolution: wontfix
Status: closednew
Triage Stage: UnreviewedReady for checkin
Type: BugNew feature
Version: 1.5master

comment:3 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 143255c8:

Fixed #22598 -- Allowed make_aware() to work with ambiguous datetime

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