Opened 8 years ago

Closed 8 years ago

#16421 closed Bug (worksforme)

Serializing TimeField throws Attribute Error

Reported by: Adam Mckerlie Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Affects version 1.2.x, 1.3


class TestModel(models.Model):
    test_time = models.TimeField()

Stack Trace

File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/core/serializers/", line 87, in serialize
    s.serialize(queryset, **options)
  File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/core/serializers/", line 45, in serialize
    self.handle_field(obj, field)
  File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/core/serializers/", line 45, in handle_field
    self._current[] = field.value_to_string(obj)
  File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/db/models/fields/", line 1103, in value_to_string
    data = val.strftime("%H:%M:%S")
AttributeError: 'unicode' object has no attribute 'strftime'

Attachments (2)

timefield.diff (584 bytes) - added by Adam Mckerlie 8 years ago.
Patch for #16421
16421-test.diff (1.4 KB) - added by Aymeric Augustin 8 years ago.

Download all attachments as: .zip

Change History (3)

Changed 8 years ago by Adam Mckerlie

Attachment: timefield.diff added

Patch for #16421

comment:1 Changed 8 years ago by Aymeric Augustin

Resolution: worksforme
Status: newclosed

I can't reproduce. I've written a test case, which I'm attaching to this ticket. I later noticed that the serialization of TimeFields is already tested by the serializers_regress tests.

Also, I believe you patch is wrong:

  • val is supposed to be a time object or None, not a string; if the function is called with a string, the error must be fixed in the caller, or further up the stack.
  • when val is a time object, the function returns a string; but with you patch, when val is a string, you're returning a time object. I don't understand this at all.

Changed 8 years ago by Aymeric Augustin

Attachment: 16421-test.diff added
Note: See TracTickets for help on using tickets.
Back to Top