Code

Opened 7 years ago

Closed 6 years ago

#5574 closed (fixed)

FileField not properly serializing to XML

Reported by: Chris Henderson <chris@…> Owned by: prairiedogg
Component: Core (Serialization) Version: master
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: UI/UX:

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@…> 7 years ago.

Download all attachments as: .zip

Change History (10)

Changed 7 years ago by Chris Henderson <chris@…>

comment:1 Changed 7 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to 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.

comment:2 Changed 7 years ago by anonymous

  • Resolution worksforme deleted
  • Status changed from closed to 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 Changed 7 years ago by cgrady

Er, the issue seems to only show up in the XML serializer, now that I look (that last comment was me btw)

comment:4 Changed 7 years ago by Chris Henderson <chris@…>

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 Changed 7 years ago by Gulopine

  • Keywords serialization, fs-rf added; serialization removed

comment:6 Changed 7 years ago by Gulopine

  • Keywords serialization added; serialization, fs-rf removed

After further research, I think this ticket is best dealt with as part of serialization, rather than in #5361.

comment:7 Changed 6 years ago by jacob

  • Triage Stage changed from Unreviewed to Accepted

comment:8 Changed 6 years ago by prairiedogg

  • Owner changed from nobody to prairiedogg
  • Status changed from reopened to new
  • Triage Stage changed from Accepted to 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 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.