Skip to content

Commit

Permalink
include root-dataset and sub-dataset in UUID-set
Browse files Browse the repository at this point in the history
This commit fixes a bug in which sub-dataset entries
in the tree-version-list and in the uuid-set would
not be added, if the dataset was a sub-dataset.

The changed code correctly re-uses the top-level
nodes that already contain the sub-dataset when
adding the super-dataset instead of cresting new,
empty top level nodes, it also adds the sub-dataset
explicitly.
  • Loading branch information
christian-monch committed Feb 23, 2023
1 parent e5d409c commit e04ab05
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions datalad_metalad/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@
from dataladmetadatamodel.metadatapath import MetadataPath
from dataladmetadatamodel.metadatarootrecord import MetadataRootRecord
from dataladmetadatamodel.uuidset import UUIDSet
from dataladmetadatamodel.versionlist import TreeVersionList
from dataladmetadatamodel.versionlist import (
TreeVersionList,
VersionList,
)
from dataladmetadatamodel.mapper.gitmapper.objectreference import flush_object_references
from dataladmetadatamodel.mapper.gitmapper.utils import locked_backend

Expand Down Expand Up @@ -472,16 +475,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 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 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 @@ -710,6 +714,22 @@ def _get_top_nodes(realm: Path,
f"dataset id {ap.dataset_id} at path {ap.dataset_path}, but "
f"the id of the stored dataset is {mrr.dataset_identifier}")

# Ensure that the UUID of the newly added dataset is in the UUID set. The
# auto_create above will only automatically create elements for the values
# in `dataset_id` and `primary_data_version`.
if ap.dataset_id not in uuid_set.uuids():
uuid_version_list = VersionList()
uuid_set.set_version_list(ap.dataset_id, uuid_version_list)
else:
uuid_version_list = uuid_set.get_version_list(ap.dataset_id)

if ap.dataset_version not in uuid_version_list.versions():
uuid_version_list.set_versioned_element(
ap.dataset_version,
str(time.time()),
ap.unversioned_path,
mrr)

return tree_version_list, uuid_set, mrr


Expand Down

0 comments on commit e04ab05

Please sign in to comment.