Opened 13 years ago

Closed 13 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

Description

Affects version 1.2.x, 1.3

Model:

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

Stack Trace

File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/core/serializers/__init__.py", line 87, in serialize
    s.serialize(queryset, **options)
  File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/core/serializers/base.py", line 45, in serialize
    self.handle_field(obj, field)
  File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/core/serializers/python.py", line 45, in handle_field
    self._current[field.name] = field.value_to_string(obj)
  File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/db/models/fields/__init__.py", 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 13 years ago.
Patch for #16421
16421-test.diff (1.4 KB ) - added by Aymeric Augustin 13 years ago.

Download all attachments as: .zip

Change History (3)

by Adam Mckerlie, 13 years ago

Attachment: timefield.diff added

Patch for #16421

comment:1 by Aymeric Augustin, 13 years ago

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.

by Aymeric Augustin, 13 years ago

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