Opened 18 years ago
Closed 18 years ago
#5574 closed (fixed)
FileField not properly serializing to XML
| Reported by: | Owned by: | prairiedogg | |
|---|---|---|---|
| Component: | Core (Serialization) | Version: | dev |
| Severity: | Keywords: | FileField, xml, serialization | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
When executing python manage.py dumpdata --format xml, FileField fields get serialized using the get_FIELD_url() method, which is causing (for me at least) this error:
Problem installing fixture 'myfixture.xml': [Errno 2] No such file or directory: u'/site_media/avatars/system/001.gif
The small attached patch fixes this problem by not treating FileField fields differently than other fields.
Attachments (1)
Change History (10)
by , 18 years ago
| Attachment: | base_serializer.diff added |
|---|
comment:1 by , 18 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
comment:2 by , 18 years ago
| Resolution: | worksforme |
|---|---|
| Status: | closed → reopened |
The issue isn't on serializing, but on trying to reload the info.
The serializer code calls get_fieldname_url instead of just outputting the database value:
elif isinstance(field, models.FileField):
value = getattr(obj, "get_%s_url" % field.name, lambda: None)()
So when you read it back in, it's got the wrong value - in his example, while the field originally held "avatars/system/001.gif", the serializers output "/site_media/avatars/system/001.gif"
comment:3 by , 18 years ago
Er, the issue seems to only show up in the XML serializer, now that I look (that last comment was me btw)
comment:4 by , 18 years ago
The "no such file or directory" error I was getting and was noted in the report was actually related to a method being called from a pre_save signal being sent to resize an image, but the underlying problem does seem to be that the value in the database is changed as cgrady noted above. Sorry for the confusing report, but I do think that there is an actual problem in the XML serializer (which is calling the base serializer for this behavior).
comment:5 by , 18 years ago
| Keywords: | fs-rf added |
|---|
comment:6 by , 18 years ago
| Keywords: | fs-rf removed |
|---|
After further research, I think this ticket is best dealt with as part of serialization, rather than in #5361.
comment:7 by , 18 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:8 by , 18 years ago
| Owner: | changed from to |
|---|---|
| Status: | reopened → new |
| Triage Stage: | Accepted → Ready for checkin |
Jacob Kaplan-Moss said that this was OK to check in even though it does not have a test. I confirmed that running this patch against the full django test suite did not produce errors, and also that it fixed the bug in my production case.
comment:9 by , 18 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
I can't reproduce the problem you describe. Furthermore, the serializers regressiontest includes cases that serialize FileFields with no actual file present.
If you can provide a sample model, fixture, and test procedure, feel free to reopen this ticket.