superset绑定数据源后,切换到图表展示时报错:
Timestamp subtraction must have the same timezones or no timezones
File "/usr/local/lib/python3.6/site-packages/superset/utils/core.py", line 362, in datetime_to_epoch return (dttm - epoch_with_tz).total_seconds() * 1000
原因:
两个时间的时区不一样,经输出发现dttm.tzinfo属性异常,估计会被误判时区,也无法根据dttm.tzinfo来调整0时间的时区,所以可以采用折中方式重新生成一个无时区的时间对象跟0时间相减来获得时间戳。
时间关系,实现方式略显笨重,不够优化,考虑性能的地方建议进一步研究彻底解决该问题。
解决方式:
/usr/local/lib/python3.6/site-packages/superset/安装路径中
修改utils/core.py的datetime_to_epoch方法
def datetime_to_epoch(dttm):
if dttm.tzinfo:
dt=datetime.strptime(dttm.strftime('%Y-%m-%d %H:%M:%S'),'%Y-%m-%d %H:%M:%S')
return (dt - EPOCH).total_seconds() * 1000
return (dttm - EPOCH).total_seconds() * 1000