#29190: timezone.is_aware() raises unhandled exception when receiving 
datetime.date
object as argument
-------------------------------------+-------------------------------------
     Reporter:  Dariem PĂ©rez         |                    Owner:  nobody
  Herrera                            |
         Type:  Bug                  |                   Status:  new
    Component:  Utilities            |                  Version:  1.11
     Severity:  Normal               |               Resolution:
     Keywords:  timezone date        |             Triage Stage:
  datetime                           |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Derek Shoemaker):

 From the code for `django.utils.timezone`:

   By design, [is_aware doesn't] perform any checks on [its] arguments. The
 caller should ensure that they don't receive an invalid value like None.

   Assuming value.tzinfo is either None or a proper datetime.tzinfo,
 value.utcoffset() implements the appropriate logic.

 So the function does not accept date objects. It only accepts datetime and
 time objects, since they the necessary time information to determine
 timezone. The date object is naive and does not have either tzinfo or
 utcoffset as methods.

 https://docs.python.org/3/library/datetime.html#datetime.date

 I don't know your use case exactly, but I think that replacing the date
 object with a datetime object will fix your problem.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29190#comment:2>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.13b0b9b02d13bcad952551625ef7433c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to