Skip to content
Snippets Groups Projects
Commit a62f3947 authored by Linus Pithan's avatar Linus Pithan
Browse files

check that metadata is only collected once

parent d3aa560f
No related branches found
No related tags found
No related merge requests found
......@@ -148,8 +148,9 @@ class Dataset:
if redis_name is None:
self._node.info["__name__"] = name
# todo this needs to move!
if self._node.info.get("__closed__") is None:
self._initialize_redis_dataset()
self.gather_metadata()
elif self._node.info.get("__closed__") is None:
raise RuntimeError(
......@@ -161,11 +162,14 @@ class Dataset:
def _log_debug(self, msg):
log_debug(self, f"Dataset({self.root_path}: {msg}")
def _initialize_redis_dataset(self):
def gather_metadata(self):
"""Initialize the dataset node info"""
if self.is_closed:
RuntimeError("dataset is already closed!")
raise RuntimeError("dataset is already closed!")
if self._node.info.get("__metadata_gathered__"):
raise RuntimeError("metadata for this dataset has already been collected!")
if current_session.icat_mapping:
metadata = current_session.icat_mapping.get_metadata()
......@@ -184,9 +188,11 @@ class Dataset:
self._node.info["__closed__"] = False
self._node.info.update(metadata)
self._node.info["__metadata_gathered__"] = True
def add_technique(self, technique):
if self.is_closed:
RuntimeError("dataset is already closed!")
raise RuntimeError("dataset is already closed!")
assert isinstance(technique, FieldGroup)
self._node.info["__techniques__"] = self._node.techniques.union(
......@@ -195,7 +201,7 @@ class Dataset:
def write_metadata_field(self, fieldname, value):
if self.is_closed:
RuntimeError("dataset is already closed!")
raise RuntimeError("dataset is already closed!")
if value is None:
if fieldname in self._node.info:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment