From 0a3d2fccd49329fd9a5d3c02f1b60e825cf06cf8 Mon Sep 17 00:00:00 2001 From: fabianmenges Date: Thu, 7 Dec 2017 19:38:22 -0500 Subject: [PATCH] [BUGFIX]: Fixing dttm_sql_literal to use python_date_format when specified. (#3891) --- superset/connectors/sqla/models.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py index 7e276a6e9..e0952288f 100644 --- a/superset/connectors/sqla/models.py +++ b/superset/connectors/sqla/models.py @@ -104,18 +104,19 @@ class TableColumn(Model, BaseColumn): 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):