Skip to content

Commit

Permalink
Merge pull request #333 from datalad/bf-update-uuid-set
Browse files Browse the repository at this point in the history
include root-dataset and sub-dataset in UUID-set
  • Loading branch information
christian-monch authored Feb 24, 2023
2 parents e5d409c + 99d9fe3 commit 9c5a61d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
29 changes: 16 additions & 13 deletions datalad_metalad/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,16 +472,17 @@ def add_finite_set(metadata_objects: List[JSONType],
tvl_us_cache=tvl_us_cache,
mrr_cache=mrr_cache)

error_result = check_dataset_ids(
metadata_store,
UUID(dataset_id),
add_parameter)

if error_result:
if not allow_id_mismatch:
yield error_result
continue
lgr.warning(error_result["message"])
if not un_versioned_path:
error_result = check_dataset_ids(
metadata_store,
UUID(dataset_id),
add_parameter)

if error_result:
if not allow_id_mismatch:
yield error_result
continue
lgr.warning(error_result["message"])

# If the key "path" is present in the metadata
# dictionary, we assume that the metadata-dictionary describes
Expand Down Expand Up @@ -673,6 +674,8 @@ def _get_top_nodes(realm: Path,
# path element in the version list (which confusingly is also called
# "path".
assert ap.dataset_path in (top_level_dataset_tree_path, None)

# We leave the creation of the respective nodes to auto_create
return get_top_nodes_and_metadata_root_record(
mapper_family=default_mapper_family,
realm=str(realm),
Expand All @@ -684,10 +687,10 @@ def _get_top_nodes(realm: Path,
sub_dataset_version=None,
auto_create=True)

# This is an aggregated add. The inter-dataset path (aka. dataset-tree-path)
# This is an aggregated add. The inter-dataset path (aka: dataset-tree-path)
# must not be "", and the un-versioned path must be "".
assert ap.dataset_path != MetadataPath("")
assert ap.unversioned_path == MetadataPath("")
assert ap.dataset_path != top_level_dataset_tree_path
assert ap.unversioned_path == top_level_dataset_tree_path

# We get the dataset tree for the root version. From this we have to load
# or create a metadata root record for the sub-dataset id and sub-dataset
Expand Down
33 changes: 17 additions & 16 deletions datalad_metalad/tests/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Test metadata adding"""
import json
import os
import tempfile
import time
from pathlib import Path
from typing import (
List,
Union,
Expand Down Expand Up @@ -79,13 +77,6 @@
}


additional_keys_unknown_template = {
"root_dataset_id": "<unknown>",
"root_dataset_version": "aaaaaaa0000000000000000222222222",
"dataset_path": "sub_0/sub_0.0/dataset_0.0.0"
}


def _assert_raise_mke_with_keys(exception_keys: List[str],
*args,
**kwargs):
Expand Down Expand Up @@ -403,7 +394,9 @@ def test_override_key_allowed(file_name=None):
def _get_top_nodes(git_repo,
dataset_id,
dataset_version,
dataset_tree_path=""):
dataset_tree_path="",
sub_dataset_id=None,
sub_dataset_version=None):

# Ensure that metadata was created
tree_version_list, uuid_set, mrr = \
Expand All @@ -414,8 +407,8 @@ def _get_top_nodes(git_repo,
primary_data_version=dataset_version,
prefix_path=MetadataPath(""),
dataset_tree_path=MetadataPath(dataset_tree_path),
sub_dataset_id=None,
sub_dataset_version=None)
sub_dataset_id=sub_dataset_id,
sub_dataset_version=sub_dataset_version)

assert_is_not_none(tree_version_list)
assert_is_not_none(uuid_set)
Expand Down Expand Up @@ -534,6 +527,8 @@ def test_subdataset_add_dataset_end_to_end(file_name=None):
assert_result_count(res, 0, type='file')

# Verify dataset level metadata was added
dataset_id = UUID(metadata_template["dataset_id"])
dataset_version = metadata_template["dataset_version"]
root_dataset_id = UUID(additional_keys_template["root_dataset_id"])
root_dataset_version = additional_keys_template["root_dataset_version"]
dataset_tree_path = MetadataPath(
Expand All @@ -543,7 +538,9 @@ def test_subdataset_add_dataset_end_to_end(file_name=None):
git_repo,
root_dataset_id,
root_dataset_version,
additional_keys_template["dataset_path"])
additional_keys_template["dataset_path"],
dataset_id,
dataset_version)

_, _, dataset_tree = tree_version_list.get_dataset_tree(
root_dataset_version,
Expand Down Expand Up @@ -585,6 +582,8 @@ def test_subdataset_add_file_end_to_end(file_name=None):
assert_result_count(res, 0, type='dataset')

# Verify dataset level metadata was added
dataset_id = UUID(metadata_template["dataset_id"])
dataset_version = metadata_template["dataset_version"]
root_dataset_id = UUID(additional_keys_template["root_dataset_id"])
root_dataset_version = additional_keys_template["root_dataset_version"]
dataset_tree_path = MetadataPath(
Expand All @@ -594,7 +593,9 @@ def test_subdataset_add_file_end_to_end(file_name=None):
git_repo,
root_dataset_id,
root_dataset_version,
additional_keys_template["dataset_path"])
additional_keys_template["dataset_path"],
dataset_id,
dataset_version)

_, _, dataset_tree = tree_version_list.get_dataset_tree(
root_dataset_version,
Expand Down Expand Up @@ -644,7 +645,7 @@ def test_current_dir_add_end_to_end(file_name=None):

expected = {
**metadata_template,
**additional_keys_unknown_template,
**additional_keys_template,
"type": "dataset",
"dataset_id": str(another_id),
}
Expand Down Expand Up @@ -703,7 +704,7 @@ def test_add_file_dump_end_to_end(file_name=None):

expected = {
**metadata_template,
**additional_keys_unknown_template,
**additional_keys_template,
"type": "file",
"path": test_path,
"dataset_id": str(another_id)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ python_requires = >= 3.7
install_requires =
six
datalad >= 0.18
datalad-metadata-model >=0.3.6
datalad-metadata-model >=0.3.10
pytest
pyyaml
test_requires =
Expand Down

0 comments on commit 9c5a61d

Please sign in to comment.