Fixed db.utils.load_backend() on non-ASCII paths.

This commit is contained in:
Tim Graham 2015-07-17 08:19:40 -04:00
parent 2f6bdab159
commit 28ee511b7e
2 changed files with 5 additions and 6 deletions

View File

@ -8,7 +8,7 @@ from threading import local
from django.conf import settings from django.conf import settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils import six from django.utils import six
from django.utils._os import upath from django.utils._os import npath, upath
from django.utils.deprecation import RemovedInDjango110Warning from django.utils.deprecation import RemovedInDjango110Warning
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.module_loading import import_string from django.utils.module_loading import import_string
@ -113,7 +113,7 @@ def load_backend(backend_name):
backend_dir = os.path.join(os.path.dirname(upath(__file__)), 'backends') backend_dir = os.path.join(os.path.dirname(upath(__file__)), 'backends')
try: try:
builtin_backends = [ builtin_backends = [
name for _, name, ispkg in pkgutil.iter_modules([backend_dir]) name for _, name, ispkg in pkgutil.iter_modules([npath(backend_dir)])
if ispkg and name not in {'base', 'dummy'}] if ispkg and name not in {'base', 'dummy'}]
except EnvironmentError: except EnvironmentError:
builtin_backends = [] builtin_backends = []

View File

@ -1,17 +1,16 @@
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.db.utils import load_backend from django.db.utils import load_backend
from django.test import SimpleTestCase from django.test import SimpleTestCase
from django.test.utils import str_prefix
from django.utils import six from django.utils import six
class TestLoadBackend(SimpleTestCase): class TestLoadBackend(SimpleTestCase):
def test_load_backend_invalid_name(self): def test_load_backend_invalid_name(self):
msg = str_prefix( msg = (
"'foo' isn't an available database backend.\n" "'foo' isn't an available database backend.\n"
"Try using 'django.db.backends.XXX', where XXX is one of:\n" "Try using 'django.db.backends.XXX', where XXX is one of:\n"
" %(_)s'mysql', %(_)s'oracle', %(_)s'postgresql_psycopg2', %(_)s'sqlite3'\n" " 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'\n"
"Error was: No module named %%s" "Error was: No module named %s"
) % "foo.base" if six.PY2 else "'foo'" ) % "foo.base" if six.PY2 else "'foo'"
with self.assertRaisesMessage(ImproperlyConfigured, msg): with self.assertRaisesMessage(ImproperlyConfigured, msg):
load_backend('foo') load_backend('foo')