Skip to content

Commit

Permalink
CLI: Fix dry-run resulting in critical error in verdi archive import (
Browse files Browse the repository at this point in the history
#6403)

The import module raises `ImportTestRun` after a dry-run of a importing
archive has finished successfully. This was not caught separately by
the `verdi archive import` command resulting in a critical error being
returned even in the case of a successful dry-run. The exception is now
caught and a success message is logged instead.
  • Loading branch information
GeigerJ2 authored May 27, 2024
1 parent e47932e commit 36991c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/aiida/cmdline/commands/cmd_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,12 @@ def _import_archive_and_migrate(

from aiida.common.folders import SandboxFolder
from aiida.tools.archive.abstract import get_format
from aiida.tools.archive.exceptions import ImportTestRun
from aiida.tools.archive.imports import import_archive as _import_archive

archive_format = get_format()
filepath = ctx.obj['config'].get_option('storage.sandbox') or None
dry_run_success = f'import dry-run of archive {archive} completed. Profile storage unmodified.'

with SandboxFolder(filepath=filepath) as temp_folder:
archive_path = archive
Expand Down Expand Up @@ -515,12 +517,19 @@ def _import_archive_and_migrate(
echo.echo_report('proceeding with import of migrated archive')
try:
_import_archive(archive_path, archive_format=archive_format, **import_kwargs)
except ImportTestRun:
echo.echo_success(dry_run_success)
return
except Exception as sub_exception:
_echo_exception(
f'an exception occurred while trying to import the migrated archive {archive}', sub_exception
)
else:
_echo_exception(f'an exception occurred while trying to import the archive {archive}', exception)
except ImportTestRun:
echo.echo_success(dry_run_success)
return

except Exception as exception:
_echo_exception(f'an exception occurred while trying to import the archive {archive}', exception)

Expand Down
13 changes: 13 additions & 0 deletions tests/cmdline/commands/test_archive_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ def test_import_archive(run_cli_command, newest_archive):
run_cli_command(cmd_archive.import_archive, options)


@pytest.mark.parametrize(
'archive',
(
get_archive_file('arithmetic.add.aiida', filepath='calcjob'),
get_archive_file('export_0.9_simple.aiida', filepath=ARCHIVE_PATH),
),
)
def test_import_dry_run(run_cli_command, archive):
"""Test import dry-run"""
result = run_cli_command(cmd_archive.import_archive, [archive, '--dry-run'])
assert f'import dry-run of archive {archive} completed' in result.output


def test_import_to_group(run_cli_command, newest_archive):
"""Test import to existing Group and that Nodes are added correctly for multiple imports of the same,
as well as separate, archives.
Expand Down

0 comments on commit 36991c6

Please sign in to comment.