Skip to content

Commit

Permalink
CLI: Fix verdi archive create --dry-run for empty file repository
Browse files Browse the repository at this point in the history
An exception was raised because no nodes were found.
  • Loading branch information
danielhollas authored and sphuber committed Mar 18, 2024
1 parent 7e42d7a commit cc96c9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/aiida/tools/archive/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,13 @@ def querybuilder():

if test_run:
EXPORT_LOGGER.report('Test Run: Stopping before archive creation')
keys = set(
orm.Node.get_collection(backend).iter_repo_keys(
filters={'id': {'in': list(entity_ids[EntityTypes.NODE])}}, batch_size=batch_size
if node_ids := list(entity_ids[EntityTypes.NODE]):
keys = set(
orm.Node.get_collection(backend).iter_repo_keys(filters={'id': {'in': node_ids}}, batch_size=batch_size)
)
)
count_summary.append(['Repository Files', len(keys)])
count_summary.append(['Repository Files', len(keys)])
else:
count_summary.append(['Repository Files', 0])
EXPORT_LOGGER.report(f'Archive would be created with:\n{tabulate(count_summary)}')
return filename

Expand Down
16 changes: 13 additions & 3 deletions tests/tools/archive/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# For further information please visit http://www.aiida.net #
###########################################################################
"""Simple tests for the export and import routines"""
import functools
import json

import pytest
Expand All @@ -24,15 +25,24 @@ def test_base_data_nodes(aiida_profile, tmp_path, entities):
values = ('Hello', 6, -1.2399834e12, False)
filename = str(tmp_path / 'export.aiida')

# Regression test for https://github.com/aiidateam/aiida-core/issues/6325
# Test run should not fail for empty DB
create_archive(None, filename=filename, test_run=True)

# producing nodes:
nodes = [cls(val).store() for val, cls in zip(values, (orm.Str, orm.Int, orm.Float, orm.Bool))]
# my uuid - list to reload the node:
uuids = [n.uuid for n in nodes]
# exporting the nodes:

if entities == 'all':
create_archive(None, filename=filename)
create = functools.partial(create_archive, None)
else:
create_archive(nodes, filename=filename)
create = functools.partial(create_archive, nodes)

# check that test run succeeds
create(filename=filename, test_run=True)
# actually export now
create(filename=filename)
# cleaning:
aiida_profile.clear_profile()
# Importing back the data:
Expand Down

0 comments on commit cc96c9d

Please sign in to comment.