Opened 6 years ago

Closed 6 years ago

#14902 closed (invalid)

Won't delete files with accents (or other unicode characters)

Reported by: typeshige Owned by: nobody
Component: Core (Other) Version: 1.2
Severity: Keywords: unicode
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I did some searches and didn't find it. I have a model with an ImageField. When I try to delete, it fails whenever the filename has accents. I'm using Linux.

/home/django/.virtualenvs/astrobiology/lib/python2.6/site-packages/django/core/files/storage.pyc in delete(self, name)

190 name = self.path(name)
191 # If the file exists, delete it from the filesystem.

--> 192 if os.path.exists(name):

193 os.remove(name)

/home/django/.virtualenvs/astrobiology/lib/python2.6/genericpath.pyc in exists(path)

16 """Test whether a path exists. Returns False for broken symbolic links"""
17 try:

---> 18 st = os.stat(path)

19 except os.error:
20 return False

UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 103: ordinal not in range(128)

Change History (2)

comment:1 Changed 6 years ago by typeshige

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

I've been doing more testing and it seems to fail on 'normal' filenames sometimes too.

It seem to fail on the same filename whenever doing something like:



import os
for i in Image.objects.all():
    print i.image.path

It fails on the same file each time, so if I isolate the offending object like this:

t = Image.objects.all(title='the problem file')

there is no problem. How can this be? Are the loops too fast?

My model Image looks like this:

class Image(models.Model):
    title = models.CharField(max_length=255)
    image = models.ImageField(upload_to=get_file_path)

comment:2 Changed 6 years ago by Karen Tracey

Resolution: invalid
Status: newclosed

Getting a UnicodeEncodeError from file system function like os.stat means your server's environment is not set up correctly to allow passing unicode strings containing non-ASCII characters to the base file system functions. See: (though that is in the mod_python doc it is not mod_python specific).

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