From 42cb5266fa9f5a6ae40221029cef7a54c559a51d Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Tue, 8 Jun 2021 18:56:55 -0700 Subject: [PATCH] fix: import metrics with extra (#15047) * fix: import metrics with extra * Fix test --- superset/datasets/commands/importers/v1/utils.py | 3 ++- tests/datasets/commands_tests.py | 2 +- tests/fixtures/importexport.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/superset/datasets/commands/importers/v1/utils.py b/superset/datasets/commands/importers/v1/utils.py index c21c66ff18..6b4dbeb7b8 100644 --- a/superset/datasets/commands/importers/v1/utils.py +++ b/superset/datasets/commands/importers/v1/utils.py @@ -98,11 +98,12 @@ def import_dataset( except TypeError: logger.info("Unable to encode `%s` field: %s", key, config[key]) for metric in config.get("metrics", []): - if metric.get("extra"): + if metric.get("extra") is not None: try: metric["extra"] = json.dumps(metric["extra"]) except TypeError: logger.info("Unable to encode `extra` field: %s", metric["extra"]) + metric["extra"] = None # should we delete columns and metrics not present in the current import? sync = ["columns", "metrics"] if overwrite else [] diff --git a/tests/datasets/commands_tests.py b/tests/datasets/commands_tests.py index 4df7365a55..1293a301ff 100644 --- a/tests/datasets/commands_tests.py +++ b/tests/datasets/commands_tests.py @@ -328,7 +328,7 @@ class TestImportDatasetsCommand(SupersetTestCase): assert metric.expression == "count(1)" assert metric.description is None assert metric.d3format is None - assert metric.extra is None + assert metric.extra == "{}" assert metric.warning_text is None assert len(dataset.columns) == 1 diff --git a/tests/fixtures/importexport.py b/tests/fixtures/importexport.py index 04aaaa3945..951ecf9bb4 100644 --- a/tests/fixtures/importexport.py +++ b/tests/fixtures/importexport.py @@ -384,7 +384,7 @@ dataset_config: Dict[str, Any] = { "expression": "count(1)", "description": None, "d3format": None, - "extra": None, + "extra": {}, "warning_text": None, }, ],