Opened 14 years ago
Closed 14 years ago
#17294 closed Bug (fixed)
django.utils.timezone functions raise AttributeError if DateTimeField allows null
| Reported by: | Daniel Swarbrick | Owned by: | Aymeric Augustin | 
|---|---|---|---|
| Component: | Internationalization | Version: | dev | 
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | yes | UI/UX: | no | 
Description
Since a null DateTimeField == None, and Python's None type does not contain a tzinfo attribute, the functions is_aware() and is_naive() will raise AttributeError.
Attachments (2)
Change History (8)
by , 14 years ago
| Attachment: | timezone.py.patch added | 
|---|
comment:1 by , 14 years ago
| Owner: | changed from to | 
|---|
comment:2 by , 14 years ago
comment:3 by , 14 years ago
Correct. My model looks like this:
class Device(models.Model): ... last_poll = models.DateTimeField(blank=True, null=True) ...
When a Device object is created, it may have the value None in the last_poll field, to be populated at some later stage.
comment:5 by , 14 years ago
Maybe instead of checking for a non-None value being passed, it might be more prudent to check isinstance(value, datetime) - or perhaps hasattr('tzinfo').
by , 14 years ago
| Attachment: | 17294.patch added | 
|---|
  Note:
 See   TracTickets
 for help on using tickets.
    
By design, these functions expect to receive a datetime object and don't check the type of their argument. It's the caller's job to ensure that they aren't called with
None, or a string, etc.If I understand correctly, creating a model with a nullable DateTimeField and saving it without a value in the admin should trigger the problem?