Opened 17 years ago

Closed 17 years ago

#5574 closed (fixed)

FileField not properly serializing to XML

Reported by: Chris Henderson <chris@…> 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)

base_serializer.diff (632 bytes ) - added by Chris Henderson <chris@…> 17 years ago.

Download all attachments as: .zip

Change History (10)

by Chris Henderson <chris@…>, 17 years ago

Attachment: base_serializer.diff added

comment:1 by Russell Keith-Magee, 17 years ago

Resolution: worksforme
Status: newclosed

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.

comment:2 by anonymous, 17 years ago

Resolution: worksforme
Status: closedreopened

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 Collin Grady, 17 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 Chris Henderson <chris@…>, 17 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 Marty Alchin, 17 years ago

Keywords: fs-rf added

comment:6 by Marty Alchin, 17 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 Jacob, 17 years ago

Triage Stage: UnreviewedAccepted

comment:8 by prairiedogg, 17 years ago

Owner: changed from nobody to prairiedogg
Status: reopenednew
Triage Stage: AcceptedReady 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 Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: newclosed

(In [7293]) Fixed #5574 -- Serialize a FileField using its filename from the database, not
external URL. The problem showed up when reloading the data. Patch from Chris
Henderson.

Note: See TracTickets for help on using tickets.
Back to Top