Fix CompositeType
Fix CompositeType bind parameter processing when of the fields is of TypeDecorator type.
This commit is contained in:
@@ -4,6 +4,12 @@ Changelog
|
||||
Here you can see the full list of changes between each SQLAlchemy-Utils release.
|
||||
|
||||
|
||||
0.30.4 (2015-05-27)
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Fixed CompositeType bind parameter processing when one of the fields is of TypeDecorator type.
|
||||
|
||||
|
||||
0.30.3 (2015-05-27)
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@@ -90,4 +90,4 @@ from .types import ( # noqa
|
||||
WeekDaysType
|
||||
)
|
||||
|
||||
__version__ = '0.30.3'
|
||||
__version__ = '0.30.4'
|
||||
|
@@ -173,6 +173,21 @@ class CompositeType(UserDefinedType, SchemaType):
|
||||
def get_col_spec(self):
|
||||
return self.name
|
||||
|
||||
def bind_processor(self, dialect):
|
||||
def process(value):
|
||||
processed_value = []
|
||||
for i, column in enumerate(self.columns):
|
||||
if isinstance(column.type, TypeDecorator):
|
||||
processed_value.append(
|
||||
column.type.process_bind_param(
|
||||
value[i], dialect
|
||||
)
|
||||
)
|
||||
else:
|
||||
processed_value.append(value[i])
|
||||
return tuple(processed_value)
|
||||
return process
|
||||
|
||||
def result_processor(self, dialect, coltype):
|
||||
def process(value):
|
||||
cls = value.__class__
|
||||
|
@@ -73,7 +73,7 @@ class TestCompositeTypeWithTypeDecorators(TestCase):
|
||||
|
||||
self.Account = Account
|
||||
|
||||
def test_parameter_processing(self):
|
||||
def test_result_set_processing(self):
|
||||
account = self.Account(
|
||||
balance=('USD', 15)
|
||||
)
|
||||
@@ -85,6 +85,18 @@ class TestCompositeTypeWithTypeDecorators(TestCase):
|
||||
assert account.balance.currency == Currency('USD')
|
||||
assert account.balance.amount == 15
|
||||
|
||||
def test_parameter_processing(self):
|
||||
account = self.Account(
|
||||
balance=(Currency('USD'), 15)
|
||||
)
|
||||
|
||||
self.session.add(account)
|
||||
self.session.commit()
|
||||
|
||||
account = self.session.query(self.Account).first()
|
||||
assert account.balance.currency == Currency('USD')
|
||||
assert account.balance.amount == 15
|
||||
|
||||
|
||||
@mark.skipif('babel is None')
|
||||
class TestCompositeTypeInsideArray(TestCase):
|
||||
|
Reference in New Issue
Block a user