fix: import metrics with extra (#15047)

* fix: import metrics with extra

* Fix test
This commit is contained in:
Beto Dealmeida 2021-06-08 18:56:55 -07:00 committed by GitHub
parent 3f527c7a45
commit 42cb5266fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 3 deletions

View File

@ -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 []

View File

@ -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

View File

@ -384,7 +384,7 @@ dataset_config: Dict[str, Any] = {
"expression": "count(1)",
"description": None,
"d3format": None,
"extra": None,
"extra": {},
"warning_text": None,
},
],