Opened 10 years ago
Closed 9 years ago
#24324 closed Bug (fixed)
Crashes when project path or path to Django install contains a non-ascii character
Reported by: | notsqrt | Owned by: | Tim Graham |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.8 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
Checked on linux, python 2.7, with Django 1.7.4.
Steps to reproduce:
mktmpenv pip install Django cd /tmp/ mkdir hého cd hého/ django-admin startproject project cd project/ python manage.py startapp app # add app to INSTALLED_APPS # add model to app.models python manage.py makemigrations app
Location:
django/db/migrations/writer.py", line 224, in path return os.path.join(basedir, self.filename)
Root of the bug: just a mix of bytes and text:
>>> import os >>> os.path.join(b'/tmp/hého', u'test') UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 6: ordinal not in range(128)
Attachments (1)
Change History (35)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
#19357 supposedly fixed all the problems in django 1.5, but I also found that the template loader fails with non-ASCII path.
Down the rabbit hole !
comment:3 by , 10 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 10 years ago
Adding a patch that fixes the reported instance, but there seems to be more work to do as the test suite still fails quite a bit.
To prevent future regressions, we could setup a Jenkins build with a name that includes some non-ASCII character like "djangō".
by , 10 years ago
Attachment: | 24324.diff added |
---|
comment:5 by , 10 years ago
When ojii and I maintained the previous iteration of the CI infrastructure, we used a build name that contained a space and a non-ASCII character in order to catch such issues.
comment:6 by , 10 years ago
Okay, I tried to setup a build with a nonascii path, but virtualenv has some problems with it. Will look into that. Similarly, I encountered virtualenv problems with spaces in the path when setting up the current CI machines.
PR to fix this ticket and some related issues. 600+ test failures remain when running test suite on a non-ascii path, but I guess it's probably only a handful of fixes. Should we try to fix all these issues on 1.7?
comment:7 by , 10 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
I've added more commits to the PR and am down to 8 failures on Python 2 on master. Investigation continues tomorrow...
virtualenv 12.0.7 (latest as of now) still seems to have trouble with non-ascii chars in the path: https://github.com/pypa/virtualenv/issues/457 so I think we are out of look unless we add some exceptions to our normal build script for the new build.
comment:8 by , 10 years ago
Patch needs improvement: | unset |
---|
Tests are passing with the latest version of the patch.
As these issues are Python 2 only and no one has complained until five months after the 1.7 release, I think we can skip fixing these issues there (absent other opinions).
comment:9 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Summary: | makemigrations fails with UnicodeDecodeError when path to project contains special characters → Crashes when project path or path to Django install contains a non-ascii character |
Version: | 1.7 → 1.8alpha1 |
comment:32 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Had trouble on the Jenkins build on Python 2 when running ./runtests.py
:
Traceback (most recent call last): File "./runtests.py", line 431, in <module> options.debug_sql) File "./runtests.py", line 253, in django_tests extra_tests=extra_tests, File "/home/jenkins/workspace/master-ἥoἥascii-path/database/sqlite3/label/trusty/python/python2.7/django/test/runner.py", line 209, in run_tests suite = self.build_suite(test_labels, extra_tests) File "/home/jenkins/workspace/master-ἥoἥascii-path/database/sqlite3/label/trusty/python/python2.7/django/test/runner.py", line 150, in build_suite tests = self.test_loader.discover(start_dir=label, **kwargs) File "/usr/lib/python2.7/unittest/loader.py", line 206, in discover tests = list(self._find_tests(start_dir, pattern)) File "/usr/lib/python2.7/unittest/loader.py", line 267, in _find_tests raise ImportError(msg % (mod_name, module_dir, expected_dir)) ImportError: u'tests' module incorrectly imported from '/home/jenkins/workspace/master-\xe1\xbc\xa5o\xe1\xbc\xa5ascii-path/database/sqlite3/label/trusty/python/python2.7/tests/shortcuts'. Expected u'/home/jenkins/workspace/master-\u1f25o\u1f25ascii-path/database/sqlite3/label/trusty/python/python2.7/tests/shortcuts'. Is this module globally installed?
but ./tests/runtests.py
works so I'm using a different build script for the build with that invocation (and also using a different virtualenv path so we avoid the non-ASCII chars). It's green now!
comment:33 by , 9 years ago
Resolution: | fixed |
---|---|
Status: | closed → new |
I don't think the solution to the problem should be "Just don't use nonascii characters in path names".
I'm not totally sure, but I suppose the problem is the unicode_literals
future import.
See Armin's opinion here: https://github.com/PythonCharmers/python-future/issues/22
I got a traceback like this:
a = '/var/lib/jenkins/jobs/K\xc3\xa1rtyarendel\xc5\x91/workspace/orders' p = ('management.py',) path = '/var/lib/jenkins/jobs/K\xc3\xa1rtyarendel\xc5\x91/workspace/orders' b = 'management.py' def join(a, *p): """Join two or more pathname components, inserting '/' as needed. If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator.""" path = a for b in p: if b.startswith('/'): path = b elif path == '' or path.endswith('/'): path += b else: > path += '/' + b E UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 23: ordinal not in range(128) /usr/lib64/python2.7/posixpath.py:80: UnicodeDecodeError
As far as I understand os.path.join
can't handle unicode inputs, but when you use the
unicode_literals
, everything will be unicode.
comment:34 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Version: | 1.8alpha1 → 1.8 |
The issue reported in this ticket is fixed in Django 1.8. Please open a new bug with steps to reproduce if you are encountering a different issue. Thanks!
As a side-note, doing the following:
fails immediately ..
So there's probably a massive work to fix all problems..