Opened 14 years ago
Closed 14 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)
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 TimeFields is already tested by the serializers_regress tests.
Also, I believe you patch is wrong:
valis 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
valis a time object, the function returns a string; but with you patch, whenvalis 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