Skip to content

Commit

Permalink
fix: import metrics with extra (apache#15047)
Browse files Browse the repository at this point in the history
* fix: import metrics with extra

* Fix test
  • Loading branch information
betodealmeida authored Jun 9, 2021
1 parent 3f527c7 commit 42cb526
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion superset/datasets/commands/importers/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
2 changes: 1 addition & 1 deletion tests/datasets/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def test_import_v1_dataset(self):
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
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/importexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
"expression": "count(1)",
"description": None,
"d3format": None,
"extra": None,
"extra": {},
"warning_text": None,
},
],
Expand Down

0 comments on commit 42cb526

Please sign in to comment.