Skip to content

Commit 6f10139

Browse files
authored
chore(sync native): Continue the import in case an error happens while getting dependencies (#344)
1 parent 46d2aac commit 6f10139

File tree

2 files changed

+76
-12
lines changed

2 files changed

+76
-12
lines changed

src/preset_cli/cli/superset/sync/native/command.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -372,24 +372,24 @@ def import_resources_individually( # pylint: disable=too-many-locals
372372

373373
asset_configs = {path: config}
374374
_logger.debug("Processing %s for import", path.relative_to("bundle"))
375-
for uuid in get_related_uuids(config):
376-
asset_configs.update(related_configs[uuid])
377-
related_configs[config["uuid"]] = asset_configs
378-
379-
if path in assets_to_skip or (
380-
asset_type != ResourceType.ASSET
381-
and asset_type.resource_name not in resource_name
382-
):
383-
continue
384-
385-
_logger.info("Importing %s", path.relative_to("bundle"))
386375
asset_log = {
387376
"uuid": config["uuid"],
388377
"path": str(path),
389378
"status": "SUCCESS",
390379
}
391-
392380
try:
381+
for uuid in get_related_uuids(config):
382+
asset_configs.update(related_configs[uuid])
383+
related_configs[config["uuid"]] = asset_configs
384+
385+
if path in assets_to_skip or (
386+
asset_type != ResourceType.ASSET
387+
and asset_type.resource_name not in resource_name
388+
):
389+
continue
390+
391+
_logger.info("Importing %s", path.relative_to("bundle"))
392+
393393
contents = {str(k): yaml.dump(v) for k, v in asset_configs.items()}
394394
import_resources(contents, client, overwrite, asset_type)
395395
except Exception: # pylint: disable=broad-except

tests/cli/superset/sync/native/command_test.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,27 @@ def test_native_split_continue( # pylint: disable=too-many-locals
12301230
},
12311231
"uuid": "5",
12321232
}
1233+
dashboard_deleted_chart = {
1234+
"dashboard_title": "Dashboard with deleted chart",
1235+
"is_managed_externally": False,
1236+
"position": {
1237+
"DASHBOARD_VERSION_KEY": "v2",
1238+
"CHART-BVI44PWH": {
1239+
"type": "CHART",
1240+
"meta": {
1241+
"uuid": "3",
1242+
},
1243+
},
1244+
"CHART-BLAH": {
1245+
"type": "CHART",
1246+
"meta": {
1247+
"uuid": None,
1248+
},
1249+
},
1250+
},
1251+
"metadata": {},
1252+
"uuid": "6",
1253+
}
12331254

12341255
fs.create_file(
12351256
root / "databases/gsheets.yaml",
@@ -1251,6 +1272,10 @@ def test_native_split_continue( # pylint: disable=too-many-locals
12511272
root / "dashboards/dashboard_deleted_dataset.yaml",
12521273
contents=yaml.dump(dashboard_deleted_dataset),
12531274
)
1275+
fs.create_file(
1276+
root / "dashboards/dashboard_deleted_chart.yaml",
1277+
contents=yaml.dump(dashboard_deleted_chart),
1278+
)
12541279

12551280
SupersetClient = mocker.patch(
12561281
"preset_cli.cli.superset.sync.native.command.SupersetClient",
@@ -1262,6 +1287,8 @@ def test_native_split_continue( # pylint: disable=too-many-locals
12621287
mocker.patch("preset_cli.cli.superset.main.UsernamePasswordAuth")
12631288
mocker.patch("preset_cli.cli.superset.lib.LOG_FILE_PATH", Path("progress.log"))
12641289

1290+
assert not Path("progress.log").exists()
1291+
12651292
runner = CliRunner()
12661293
result = runner.invoke(
12671294
superset_cli,
@@ -1330,6 +1357,43 @@ def test_native_split_continue( # pylint: disable=too-many-locals
13301357
any_order=True,
13311358
)
13321359

1360+
with open("progress.log", encoding="utf-8") as log:
1361+
content = yaml.load(log, Loader=yaml.SafeLoader)
1362+
1363+
assert content["ownership"] == []
1364+
assert content["assets"] == [
1365+
{
1366+
"path": "bundle/databases/gsheets.yaml",
1367+
"uuid": "1",
1368+
"status": "SUCCESS",
1369+
},
1370+
{
1371+
"path": "bundle/datasets/gsheets/test.yaml",
1372+
"uuid": "2",
1373+
"status": "SUCCESS",
1374+
},
1375+
{
1376+
"path": "bundle/charts/chart.yaml",
1377+
"uuid": "3",
1378+
"status": "SUCCESS",
1379+
},
1380+
{
1381+
"path": "bundle/dashboards/dashboard_deleted_chart.yaml",
1382+
"uuid": "6",
1383+
"status": "FAILED",
1384+
},
1385+
{
1386+
"path": "bundle/dashboards/dashboard_deleted_dataset.yaml",
1387+
"uuid": "5",
1388+
"status": "SUCCESS",
1389+
},
1390+
{
1391+
"path": "bundle/dashboards/dashboard.yaml",
1392+
"uuid": "4",
1393+
"status": "SUCCESS",
1394+
},
1395+
]
1396+
13331397

13341398
def test_native_continue_without_split(
13351399
mocker: MockerFixture,

0 commit comments

Comments
 (0)