Made Arrow and IPAddress types use ScalarCoercible
This commit is contained in:
@@ -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):
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user