Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow unicode database identifiers in Python 2 #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dynamic_db_router/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from uuid import uuid4

from django.db import connections
from django.utils import six


THREAD_LOCAL = threading.local()

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions dynamic_db_router/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
subprocess.call(['python', 'setup.py', 'register', 'sdist', 'bdist_wheel', 'upload'])