Opened 11 years ago

Closed 11 years ago

Last modified 7 years ago

#8466 closed (worksforme)

FileField path url dumpdata/loaddata issue

Reported by: Ian Ward Owned by: nobody
Component: Core (Serialization) Version: master
Severity: Keywords: FileField path url
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have a model that includes a FileField with values such as "/media/uploaded/YEAR/MONTH/NAME" (upload_to='%Y/%m').
I upgraded to Django 1.0 beta svn-8457 and switched from using get_filefiledname_size() to filefiedname.size.
Now, this property triggers a SuspiciousOperation exception: When is called,
it calls safe_join and decides that the leading slash in the file path puts the file outside of the media root directory.

New instances of this model include a leading slash in the path, so this doesn't seem to be a change
to how the file name is stored.

Change History (4)

comment:1 Changed 11 years ago by Ian Ward

Component: File uploads/storageSerialization
Keywords: path url added; size removed
Summary: FileField.size triggering SuspiciousOperation exceptionFileField path url dumpdata/loaddata issue

Now, this looks like an export issue. I dumped the models into an XML file from a Postgres database where the file paths looked like:
YEAR/MONTH/NAME. The XML file contains "/media/uploaded/YEAR/MONTH/NAME" and when importing to sqlite the database contains "/media/uploaded/YEAR/MONTH/NAME", causing the problem above.

new instances of the model *do not* contain /media/uploaded/ in the database, it just looked that way from the admin site.

comment:2 Changed 11 years ago by Collin Grady

I can't seem to duplicate this - the xml serializer had an old bug where it used get_fieldname_url() instead of just fieldname, but that was fixed (#5574)

with current trunk, I get this on serializing filefields:

<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">
  <object pk="1" model="locked.filetest">
    <field type="FileField" name="test">test/en-NG_.msi</field>

which does not include MEDIA_ROOT or MEDIA_URL

comment:3 Changed 11 years ago by Ian Ward

Resolution: worksforme
Status: newclosed

Then it must have been because I was exporting from a version afflicted with that bug. Thanks cgrady.

comment:4 Changed 7 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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