Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to import dataset asset with no 'targets' field like filter divider #321

Merged
merged 8 commits into from
Oct 25, 2024
3 changes: 1 addition & 2 deletions src/preset_cli/cli/superset/sync/native/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ def native( # pylint: disable=too-many-locals, too-many-arguments, too-many-bra
url = URL(ctx.obj["INSTANCE"])
client = SupersetClient(url, auth)
root = Path(directory)

base_url = URL(external_url_prefix) if external_url_prefix else None

# collecting existing database UUIDs so we know if we're creating or updating
Expand Down Expand Up @@ -382,7 +381,7 @@ def get_dataset_filter_uuids(config: AssetConfig) -> Set[str]:
"""
dataset_uuids = set()
for filter_config in config["metadata"].get("native_filter_configuration", []):
for target in filter_config["targets"]:
for target in filter_config.get("targets", {}):
if uuid := target.get("datasetUuid"):
if uuid not in dataset_uuids:
dataset_uuids.add(uuid)
Expand Down
40 changes: 40 additions & 0 deletions tests/cli/superset/sync/native/command_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests for the native import command.
"""

# pylint: disable=redefined-outer-name, invalid-name, too-many-lines

import json
Expand Down Expand Up @@ -896,6 +897,27 @@ def test_native_split( # pylint: disable=too-many-locals
},
"uuid": "6",
}

dashboard_with_filter_divider_config = {
"dashboard_title": "Some dashboard",
"is_managed_externally": False,
"position": {},
"metadata": {
"native_filter_configuration": [
{
"type": "NATIVE_FILTER",
"targets": [
{
"column": "some_column",
"datasetUuid": "5",
},
],
},
{"type": "DIVIDER", "targets": {}},
],
},
"uuid": "7",
}
fs.create_file(
root / "databases/gsheets.yaml",
contents=yaml.dump(database_config),
Expand Down Expand Up @@ -928,6 +950,10 @@ def test_native_split( # pylint: disable=too-many-locals
root / "dashboards/dashboard_deleted_dataset.yaml",
contents=yaml.dump(dashboard_deleted_dataset),
)
fs.create_file(
root / "dashboards/dashboard_with_filter_divider_config.yaml",
contents=yaml.dump(dashboard_with_filter_divider_config),
)

SupersetClient = mocker.patch(
"preset_cli.cli.superset.sync.native.command.SupersetClient",
Expand Down Expand Up @@ -1023,7 +1049,21 @@ def test_native_split( # pylint: disable=too-many-locals
client,
False,
),
mock.call(
{
"bundle/dashboards/dashboard_with_filter_divider_config.yaml": yaml.dump(
dashboard_with_filter_divider_config,
),
"bundle/datasets/gsheets/filter_test.yaml": yaml.dump(
dataset_filter_config,
),
"bundle/databases/gsheets.yaml": yaml.dump(database_config),
},
client,
False,
),
],
any_order=True,
)


Expand Down
Loading