Skip to content

Commit

Permalink
use FixedOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbanin committed Aug 12, 2019
1 parent 27a98cb commit e78a08d
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions plugins/snowflake/dbt/adapters/snowflake/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,6 @@
from dbt.logger import GLOBAL_LOGGER as logger


# Provide a sane Timezone that can be pickled
# The datetime objects returned by snowflake-connector-python
# are not currently pickleable, so they can't be shared across
# process boundaries (ie. in the dbt rpc server)
# See: https:/snowflakedb/snowflake-connector-python/pull/188
class OffsetTimezone(datetime.tzinfo):
def __init__(self, name, tzoffset_seconds):
self.name = name
self.tzoffset = datetime.timedelta(seconds=tzoffset_seconds)

def utcoffset(self, dt, is_dst=False):
return self.tzoffset

def tzname(self, dt):
return self.name

def dst(self, dt):
return datetime.timedelta(0)

def __repr__(self):
return self.name


SNOWFLAKE_CREDENTIALS_CONTRACT = {
'type': 'object',
'additionalProperties': False,
Expand Down Expand Up @@ -233,9 +210,7 @@ def process_results(cls, column_names, rows):
if isinstance(col, datetime.datetime) and col.tzinfo:
offset = col.utcoffset()
offset_seconds = offset.total_seconds()
new_timezone = OffsetTimezone(
dbt.compat.to_native_string(col.tzinfo.tzname(col)),
offset_seconds)
new_timezone = pytz.FixedOffset(offset_seconds // 60)
col = col.astimezone(tz=new_timezone)
fixed_row.append(col)

Expand Down

0 comments on commit e78a08d

Please sign in to comment.