Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
from infi.clickhouse_orm.models import ModelBase
from infi.clickhouse_orm.database import Database

# fix local timezone
from tzlocal import get_localzone
import os
# fixed local timezone

# PEP 249 module globals
apilevel = '2.0'
threadsafety = 2 # Threads may share the module and connections.
Expand Down Expand Up @@ -355,7 +360,17 @@ def _process_response(self, response):
for r in response:
if not cols:
cols = [(f, r._fields[f].db_type) for f in r._fields]
data.append([getattr(r, f) for f in r._fields])
vals = []
for fi in r._fields:
val = getattr(r, fi)

clickhouseUseLocalTimezone = int(os.getenv('CLICKHOUSE_USE_LOCAL_TIMEZONE', '0'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you set the variable in the module header with other settings (instead of inside the loop)?

if clickhouseUseLocalTimezone and (r._fields[fi].db_type == 'DateTime' or r._fields[fi].db_type == 'Date'):
val = val.astimezone(get_localzone())

vals.append(val)
data.append(vals)
# data.append([getattr(r, f) for f in r._fields])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the commented text?

self._data = data
self._columns = cols
self._state = self._STATE_FINISHED