Opened 10 years ago

Closed 9 years ago

#2923 closed defect (fixed)

[patch] FileField does not allow modifications on Windows

Reported by: radek Owned by: Adrian Holovaty
Component: contrib.admin Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:


When you have FileField (or ImageField) and use Django on Windows, second time uploaded filename is always considered invalid.
Ie. you can create one instance, but you can't go back and edit this one and save. You always get:

Enter a valid filename.

The issue is in

\django\trunk\django\db\models\fields\ on line 579

os.path.abspath(os.path.join(settings.MEDIA_ROOT, field_data)):

will give:

while this



You can see missing Drive name.

Patch is here:

@@ -576,7 +576,7 @@
         # If the raw path is passed in, validate it's under the MEDIA_ROOT.
         def isWithinMediaRoot(field_data, all_data):
             f = os.path.abspath(os.path.join(settings.MEDIA_ROOT, field_data))
-            if not f.startswith(os.path.normpath(settings.MEDIA_ROOT)):
+            if not f.startswith(os.path.abspath(os.path.normpath(settings.MEDIA_ROOT))):
                 raise validators.ValidationError, _("Enter a valid filename.")
         return field_list

Pitty I spent a whole day, before I found it.

Attachments (1)

2923.patch (713 bytes) - added by justin.driscoll@… 9 years ago.
Strip forward slash from "field_data" in "isWithinMediaRoot".

Download all attachments as: .zip

Change History (8)

comment:1 Changed 10 years ago by Chris Beaven

Summary: FileField does not allow modifications on Windows[patch] FileField does not allow modifications on Windows

Just marking that this contains a patch.

comment:2 Changed 10 years ago by Adrian Holovaty

priority: highestnormal
Severity: blockernormal

comment:3 Changed 10 years ago by anonymous

Resolution: fixed
Status: newclosed

comment:4 Changed 10 years ago by Chris Beaven

Just confirming the fix since it's unusual that tickets are closed by anonymous.

This was fixed in [4036].

comment:5 Changed 10 years ago by (none)

milestone: Version 1.0

Milestone Version 1.0 deleted

comment:6 Changed 9 years ago by justin.driscoll@…

Patch needs improvement: set
Resolution: fixed
Status: closedreopened

The current patch did not solve what seems to be the same problem for me. A forward slash appended to the beginning "field_data" was causing "os.path.abspath(os.path.join(settings.MEDIA_ROOT, field_data))" to return an incorrect path and raise a validation error.

Changed 9 years ago by justin.driscoll@…

Attachment: 2923.patch added

Strip forward slash from "field_data" in "isWithinMediaRoot".

comment:7 Changed 9 years ago by Malcolm Tredinnick

Resolution: fixed
Status: reopenedclosed

Justin, please open a new ticket with your problem and an explanation of how to repeat it. That will help use keep comments on the new change separate from the history for this ticket.

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