use BaseTzInfo since pytz also uses StaticTzInfo

This commit is contained in:
Stephen J. Fuhry
2016-09-24 14:58:22 -04:00
parent f1f2a905d7
commit b48a7bd6b6

View File

@@ -52,9 +52,10 @@ class TimezoneType(types.TypeDecorator, ScalarCoercible):
elif backend == 'pytz': elif backend == 'pytz':
try: try:
from pytz import tzfile, timezone from pytz import timezone
from pytz.tzinfo import BaseTzInfo
self.python_type = tzfile.DstTzInfo self.python_type = BaseTzInfo
self._to = timezone self._to = timezone
self._from = six.text_type self._from = six.text_type
@@ -71,13 +72,11 @@ class TimezoneType(types.TypeDecorator, ScalarCoercible):
) )
def _coerce(self, value): def _coerce(self, value):
if value and not isinstance(value, self.python_type): if value is not None and not isinstance(value, self.python_type):
obj = self._to(value) obj = self._to(value)
if obj is None: if obj is None:
raise ValueError("unknown time zone '%s'" % value) raise ValueError("unknown time zone '%s'" % value)
return obj return obj
return value return value
def process_bind_param(self, value, dialect): def process_bind_param(self, value, dialect):