#32661: An exception should be raised when trying to save an aware datetime/time
object even when the UTC offset isn't known.
-------------------------------------+-------------------------------------
     Reporter:  Armin Stepanjan      |                    Owner:  Abhyudai
         Type:                       |                   Status:  closed
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  timezone, datetime,  |             Triage Stage:  Accepted
  datetimefield, timefield, models   |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

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


Comment:

 `datetime`/`time` objects with `tzinfo` which don't declare `utcoffset`
 should be treated as naive. Closing as invalid per Aymeric's
 [https://github.com/django/django/pull/14583#issuecomment-873395340
 comment]:
 {{{
 This code has been working well for over 10 years so let's be careful.
 Here's my analysis.

 The docs say:

 > A datetime object d is aware if both of the following hold:
 >
 > 1. d.tzinfo is not None
 > 2. d.tzinfo.utcoffset(d) does not return None
 >
 > Otherwise, d is naive.

 This hasn't changed this Python 2.7. (I didn't check further back.)

 This was explicitly the implementation before
 432678dbc1dd4f80203468d83bb0eb6c20ed5247.

 Also, the documentation of datetime.utcoffset, `value.utcoffset()`
 literally implemented as `None if value.tzinfo is None else
 value.tzinfo.utcoffset(value)`.

 As a consequence of the above, each of the following propositions are
 strictly equivalent:

 ...

 Therefore I believe the change proposed here is wrong for at least three
 reasons:

 - Any logic changes in this area will diverge from the definition in the
 Python docs.
 - The proposed logic is redundant — if `value.tzinfo is None`, then
 `value.utcoffset() is None`: this is the first six words of the
 documentation of datetime.utcoffset: "If tzinfo is None, returns None"; I
 don't see how adding this redundant logic is an improvement.
 - The proposed logic is wrong — if you wanted to go back to the previous
 implementation, you should use `and` instead of `or` in `is_naive`.

 Finally, I believe that have two one-liner convenience functions
 implemented as `value.utcoffset() is None` and `value.utcoffset() is not
 None` is fine. I don't see the need for adding a level of indirection and
 the overhead of a function call here.
 }}}

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.d8ae82fa1a7cdbcf9cfbfca8e19fcb1e%40djangoproject.com.

Reply via email to