Skip to content

Commit

Permalink
allow duplicate relative_path in case dataset is not copied
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanneBogart committed Oct 24, 2024
1 parent 9d2bb02 commit 2802144
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
27 changes: 19 additions & 8 deletions src/dataregistry/registrar/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ def register(

# Make sure the relative_path in the `root_dir` is avaliable
if kwargs_dict["location_type"] in ["dataregistry", "dummy"]:
will_copy = kwargs_dict["old_location"]
previous_datasets = self._find_previous(
None,
None,
Expand All @@ -433,17 +434,27 @@ def register(
root_dir=self._root_dir,
)

warned = False
if get_dataset_status(previous_datasets[-1].status, "archived"):
raise ValueError(
f"Relative path {dest} is reserved "
f"for archived datasetid={previous_datasets[-1].dataset_id}"
)
if will_copy:
raise ValueError(
f"Relative path {dest} is reserved "
f"for archived datasetid={previous_datasets[-1].dataset_id}"
)
else:
print(f"Warning: found existing entry with path {kwargs_dict['relative_path']}")
warned = True

if not get_dataset_status(previous_datasets[-1].status, "deleted"):
raise ValueError(
f"Relative path {dest} is taken by "
f"datasetid={previous_datasets[-1].dataset_id}"
)
if will_copy:
raise ValueError(
f"Relative path {dest} is taken by "
f"datasetid={previous_datasets[-1].dataset_id}"
)
else:
if not warned:
print(f"Warning: found existing entry with path {kwargs_dict['relative_path']}")


# Make sure there is not already a database entry with this
# name/version combination
Expand Down
8 changes: 6 additions & 2 deletions tests/end_to_end_tests/test_register_dataset_real_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def test_copy_data(dummy_file, data_org):
[
("file", "file1.txt"),
("directory", "dummy_dir"),
("same_directory", "dummy_dir")
],
)
def test_on_location_data(dummy_file, data_org, data_path):
Expand Down Expand Up @@ -84,9 +85,12 @@ def test_on_location_data(dummy_file, data_org, data_path):
[f],
)

assert len(results["dataset.data_org"]) == 1
if data_org == "same_directory":
assert len(results["dataset.data_org"]) == 2
else:
assert len(results["dataset.data_org"]) == 1

assert results["dataset.data_org"][0] == data_org
assert results["dataset.data_org"][0].endswith(data_org)
assert results["dataset.nfiles"][0] == 1
assert results["dataset.total_disk_space"][0] > 0

Expand Down

0 comments on commit 2802144

Please sign in to comment.