diff --git a/lib/cartodb/models/mapconfig/adapter/vector-mapconfig-adapter.js b/lib/cartodb/models/mapconfig/adapter/vector-mapconfig-adapter.js index 211c574b..a707b5d3 100644 --- a/lib/cartodb/models/mapconfig/adapter/vector-mapconfig-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/vector-mapconfig-adapter.js @@ -28,7 +28,7 @@ class VectorMapConfigAdapter { } _wrapLayer(layer, user) { - if (!layer.options.dates_as_numbers) { + if (!layer.options.dates_as_numbers || !layer.options.sql) { return Promise.resolve(layer); } const originalQuery = layer.options.sql; diff --git a/lib/cartodb/utils/date-wrapper.js b/lib/cartodb/utils/date-wrapper.js index 3c0907f1..d07d43c1 100644 --- a/lib/cartodb/utils/date-wrapper.js +++ b/lib/cartodb/utils/date-wrapper.js @@ -35,17 +35,19 @@ function _castColumnToEpoch(columnName) { } function wrappedDates(query) { - if (query.match(/\b_cdb_epoch_transformation\b/)) { - const columns = []; - const fieldMatcher = /\bdate_part\('epoch', "([^"]+)"\) as "([^"]+)"/gmi; - let match; - do { - match = fieldMatcher.exec(query); - if (match && match[1] === match[2]) { - columns.push(match[1]); - } - } while (match); - return columns; + if (query) { + if (query.match(/\b_cdb_epoch_transformation\b/)) { + const columns = []; + const fieldMatcher = /\bdate_part\('epoch', "([^"]+)"\) as "([^"]+)"/gmi; + let match; + do { + match = fieldMatcher.exec(query); + if (match && match[1] === match[2]) { + columns.push(match[1]); + } + } while (match); + return columns; + } } } diff --git a/lib/cartodb/utils/layergroup-metadata.js b/lib/cartodb/utils/layergroup-metadata.js index 62a3cd73..65fb8f4a 100644 --- a/lib/cartodb/utils/layergroup-metadata.js +++ b/lib/cartodb/utils/layergroup-metadata.js @@ -172,9 +172,12 @@ module.exports = class LayergroupMetadata { if (layergroup.metadata && Array.isArray(layergroup.metadata.layers) && Array.isArray(mapConfig.layers)) { layergroup.metadata.layers = layergroup.metadata.layers.map(function(layer, layerIndex) { const mapConfigLayer = mapConfig.layers[layerIndex]; - const wrappedColumns = dateWrapper.wrappedDates(mapConfigLayer.options.sql); - if (wrappedColumns) { - layer.meta.dates_as_numbers = wrappedColumns; + const layerOptions = mapConfigLayer.options; + if (layerOptions.dates_as_numbers && layerOptions.sql) { + const wrappedColumns = dateWrapper.wrappedDates(layerOptions.sql); + if (wrappedColumns) { + layer.meta.dates_as_numbers = wrappedColumns; + } } return layer; });