diff --git a/dynamic_db_router/router.py b/dynamic_db_router/router.py index f768832..41d2665 100644 --- a/dynamic_db_router/router.py +++ b/dynamic_db_router/router.py @@ -3,6 +3,8 @@ from uuid import uuid4 from django.db import connections +from django.utils import six + THREAD_LOCAL = threading.local() @@ -84,7 +86,7 @@ def __init__(self, database, read=True, write=False): self.read = read self.write = write self.created_db_config = False - if isinstance(database, str): + if isinstance(database, six.string_types): self.database = database elif isinstance(database, dict): # Note: this invalidates the docs above. Update them diff --git a/dynamic_db_router/tests/tests.py b/dynamic_db_router/tests/tests.py index c4ec7f9..81d0ace 100644 --- a/dynamic_db_router/tests/tests.py +++ b/dynamic_db_router/tests/tests.py @@ -3,6 +3,7 @@ from django.db import connections from django.test import TestCase +from django.utils import six from django_dynamic_fixture import G from dynamic_db_router import DynamicDbRouter, in_database @@ -19,6 +20,13 @@ def test_string_identifier(self): expected = 1 self.assertEqual(count, expected) + def test_unicode_identifier(self): + G(TestModel, name='Arnold') + with in_database(six.text_type('default')): + count = TestModel.objects.count() + expected = 1 + self.assertEqual(count, expected) + def test_readonly_connection_writes_to_default(self): with in_database('test'): G(TestModel, name='Arnold') diff --git a/publish.py b/publish.py index a363e3f..7fd2587 100644 --- a/publish.py +++ b/publish.py @@ -2,4 +2,4 @@ subprocess.call(['pip', 'install', 'wheel']) subprocess.call(['python', 'setup.py', 'clean', '--all']) -subprocess.call(['python', 'setup.py', 'register', 'sdist', 'bdist_wheel', 'upload']) \ No newline at end of file +subprocess.call(['python', 'setup.py', 'register', 'sdist', 'bdist_wheel', 'upload'])