Opened 14 years ago
Closed 14 years ago
#16421 closed Bug (worksforme)
Serializing TimeField throws Attribute Error
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'
Change History (3)
by , 14 years ago
Attachment: | timefield.diff added |
---|
comment:1 by , 14 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
I can't reproduce. I've written a test case, which I'm attaching to this ticket. I later noticed that the serialization of TimeField
s is already tested by the serializers_regress
tests.
Also, I believe you patch is wrong:
val
is supposed to be a time object orNone
, 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, whenval
is a string, you're returning a time object. I don't understand this at all.
by , 14 years ago
Attachment: | 16421-test.diff added |
---|
Note:
See TracTickets
for help on using tickets.
Patch for #16421