Skip to content

Commit

Permalink
[BUGFIX]: Fixing dttm_sql_literal to use python_date_format when spec…
Browse files Browse the repository at this point in the history
…ified. (apache#3891)
  • Loading branch information
fabianmenges authored and michellethomas committed May 23, 2018
1 parent 7be8f3f commit 39d7658
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,19 @@ def dttm_sql_literal(self, dttm):
If database_expression is not empty, the internal dttm
will be parsed as the sql sentence for the database to convert
"""

tf = self.python_date_format or '%Y-%m-%d %H:%M:%S.%f'
tf = self.python_date_format
if self.database_expression:
return self.database_expression.format(dttm.strftime('%Y-%m-%d %H:%M:%S'))
elif tf == 'epoch_s':
return str((dttm - datetime(1970, 1, 1)).total_seconds())
elif tf == 'epoch_ms':
return str((dttm - datetime(1970, 1, 1)).total_seconds() * 1000.0)
elif tf:
if tf == 'epoch_s':
return str((dttm - datetime(1970, 1, 1)).total_seconds())
elif tf == 'epoch_ms':
return str((dttm - datetime(1970, 1, 1)).total_seconds() * 1000.0)
return "'{}'".format(dttm.strftime(tf))
else:
s = self.table.database.db_engine_spec.convert_dttm(
self.type or '', dttm)
return s or "'{}'".format(dttm.strftime(tf))
return s or "'{}'".format(dttm.strftime('%Y-%m-%d %H:%M:%S.%f'))


class SqlMetric(Model, BaseMetric):
Expand Down

0 comments on commit 39d7658

Please sign in to comment.