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

U/jrbogart/allowing duplicate relpath #161

Merged
merged 3 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 data_org.endswith(results["dataset.data_org"][0])
assert results["dataset.nfiles"][0] == 1
assert results["dataset.total_disk_space"][0] > 0

Expand Down
Loading