Opened 18 years ago
Closed 17 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: | dev |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
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\init.py on line 579
Because
os.path.abspath(os.path.join(settings.MEDIA_ROOT, field_data)):
will give:
'D:
www
myproject
media
subfolder
1-icon.png'
while this
os.path.normpath(settings.MEDIA_ROOT):
gives:
'
www
myproject
media'
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.") field_list[1].validator_list.append(isWithinMediaRoot) return field_list
Pitty I spent a whole day, before I found it.
Attachments (1)
Change History (8)
comment:1 by , 18 years ago
Summary: | FileField does not allow modifications on Windows → [patch] FileField does not allow modifications on Windows |
---|
comment:2 by , 18 years ago
priority: | highest → normal |
---|---|
Severity: | blocker → normal |
comment:3 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 by , 18 years ago
Just confirming the fix since it's unusual that tickets are closed by anonymous.
This was fixed in [4036].
comment:6 by , 17 years ago
Patch needs improvement: | set |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
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.
by , 17 years ago
Attachment: | 2923.patch added |
---|
Strip forward slash from "field_data" in "isWithinMediaRoot".
comment:7 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
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.
Just marking that this contains a patch.