Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#10905 closed (worksforme)

UnicodeEncodeError from FileUploadTests.test_unicode_file_name

Reported by: Richard Davies <richard.davies@…> Owned by: nobody
Component: File uploads/storage Version:
Severity: Keywords:
Cc: richard.davies@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Running the test suite on a clean check out of r10628, I get:

======================================================================
ERROR: test_unicode_file_name (regressiontests.file_uploads.tests.FileUploadTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/elastic-www/test/trunk/tests/regressiontests/file_uploads/tests.py", line 67, in test_unicode_file_name
    response = self.client.post('/file_uploads/unicode_name/', post_data)
  File "/home/elastic-www/test/trunk/django/test/client.py", line 313, in post
    response = self.request(**r)
  File "/home/elastic-www/test/trunk/django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/elastic-www/test/trunk/tests/regressiontests/file_uploads/views.py", line 64, in file_upload_unicode_name
    obj = FileModel.objects.create(testfile=uni_named_file)
  File "/home/elastic-www/test/trunk/django/db/models/manager.py", line 126, in create
    return self.get_query_set().create(**kwargs)
  File "/home/elastic-www/test/trunk/django/db/models/query.py", line 284, in create
    obj.save(force_insert=True)
  File "/home/elastic-www/test/trunk/django/db/models/base.py", line 407, in save
    self.save_base(force_insert=force_insert, force_update=force_update)
  File "/home/elastic-www/test/trunk/django/db/models/base.py", line 471, in save_base
    values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, True))) for f in meta.local_fields if not isinstance(f, AutoField)]
  File "/home/elastic-www/test/trunk/django/db/models/fields/files.py", line 191, in pre_save
    file.save(file.name, file, save=False)
  File "/home/elastic-www/test/trunk/django/db/models/fields/files.py", line 83, in save
    self._name = self.storage.save(name, content)
  File "/home/elastic-www/test/trunk/django/core/files/storage.py", line 46, in save
    name = self.get_available_name(name)
  File "/home/elastic-www/test/trunk/django/core/files/storage.py", line 68, in get_available_name
    while self.exists(name):
  File "/home/elastic-www/test/trunk/django/core/files/storage.py", line 198, in exists
    return os.path.exists(self.path(name))
  File "/lib/python2.5/posixpath.py", line 171, in exists
    st = os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 43-44: ordinal not in range(128)

My command line to run the tests was:

$ cat settings.py
DATABASE_ENGINE='sqlite3'
$ ./runtests.py --settings=settings file_uploads

Change History (4)

comment:1 by Richard Davies <richard.davies@…>, 16 years ago

Version: 1.0

comment:2 by Karen Tracey, 16 years ago

What is your LANG set to? You are seeing a failure often seen under Apache due to an incorrect LANG setting:

http://code.djangoproject.com/wiki/django_apache_and_mod_wsgi#AdditionalTweaking

I suspect you have LANG set to something like C, which results in the ascii codec being used for encoding unicode file paths passed into system calls. As the file path for that test can't be represented in ASCII, you get an error. Setting LANG to something like 'en_US.UTF-8' will cause the utf8 codec to be used for encoding file paths to bytestrings, and the test will pass.

comment:3 by Jacob, 16 years ago

Resolution: worksforme
Status: newclosed

See Karen's note: unicode path support only works if your filesystem does.

comment:4 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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