Fix encoding issue with MySQL

This commit is contained in:
Konsta Vesterinen
2016-01-15 10:06:48 +02:00
parent fafd74b058
commit 05fc1740e4
2 changed files with 6 additions and 4 deletions

View File

@@ -66,10 +66,12 @@ class WeekDaysType(types.TypeDecorator, ScalarCoercible):
def process_bind_param(self, value, dialect):
if isinstance(value, WeekDays):
return value.as_bit_string()
value = value.as_bit_string()
if isinstance(value, six.string_types):
return value
if dialect.name == 'mysql':
func = bytes if six.PY3 else bytearray
return func(value, 'utf8')
return value
def process_result_value(self, value, dialect):
if value is not None:

View File

@@ -35,7 +35,7 @@ class WeekDaysTypeTestCase(TestCase):
assert isinstance(schedule.working_days, WeekDays)
def test_scalar_attributes_get_coerced_to_objects(self):
schedule = self.Schedule(working_days=u'1010101')
schedule = self.Schedule(working_days='1010101')
assert isinstance(schedule.working_days, WeekDays)