From 576edb19a5cde7320339788fbf019519838ae5d3 Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Thu, 24 Oct 2013 11:31:04 +0300 Subject: [PATCH] Made Arrow and IPAddress types use ScalarCoercible --- sqlalchemy_utils/types/arrow.py | 5 +++-- sqlalchemy_utils/types/ip_address.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sqlalchemy_utils/types/arrow.py b/sqlalchemy_utils/types/arrow.py index 4d669e5..4394acc 100644 --- a/sqlalchemy_utils/types/arrow.py +++ b/sqlalchemy_utils/types/arrow.py @@ -10,9 +10,10 @@ except: pass from sqlalchemy import types from sqlalchemy_utils import ImproperlyConfigured +from .scalar_coercible import ScalarCoercible -class ArrowType(types.TypeDecorator): +class ArrowType(types.TypeDecorator, ScalarCoercible): impl = types.DateTime def __init__(self, *args, **kwargs): @@ -33,7 +34,7 @@ class ArrowType(types.TypeDecorator): return arrow.get(value) return value - def coercion_listener(self, target, value, oldvalue, initiator): + def _coerce(self, value): if value is None: return None elif isinstance(value, six.string_types): diff --git a/sqlalchemy_utils/types/ip_address.py b/sqlalchemy_utils/types/ip_address.py index d936e2f..de0db23 100644 --- a/sqlalchemy_utils/types/ip_address.py +++ b/sqlalchemy_utils/types/ip_address.py @@ -12,9 +12,10 @@ except ImportError: from sqlalchemy import types from sqlalchemy_utils import ImproperlyConfigured +from .scalar_coercible import ScalarCoercible -class IPAddressType(types.TypeDecorator): +class IPAddressType(types.TypeDecorator, ScalarCoercible): """ Changes IPAddress objects to a string representation on the way in and changes them back to IPAddress objects on the way out. @@ -38,5 +39,5 @@ class IPAddressType(types.TypeDecorator): def process_result_value(self, value, dialect): return ip_address(value) if value else None - def coercion_listener(self, target, value, oldvalue, initiator): + def _coerce(self, value): return ip_address(value) if value else None