Skip to content
Snippets Groups Projects
Commit 3093cc1e authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

FIX: identifiables used as references in properties of identifiables are now retrieved

parent 4d301ed1
No related branches found
No related tags found
1 merge request!53Release 0.1
!!python/object/apply:collections.defaultdict
args:
- !!python/name:newcrawler.crawl.%3Clambda%3E ''
dictitems:
Measurement:
date: !!python/tuple
- - SimulationData
- 2020_climate-model-predict
- '2020-02-01'
- - SimulationData
- project_dir
- measurement
description: !!python/tuple
- - SimulationData
- 2020_climate-model-predict
- '2020-02-01'
- README.md
- description
- - SimulationData
- project_dir
- measurement
- README
- description
identifier: !!python/tuple
- - SimulationData
- 2020_climate-model-predict
- '2020-02-01'
- - SimulationData
- project_dir
- measurement
project: !!python/tuple
- - SimulationData
- 2020_climate-model-predict
- '2020-02-01'
- - SimulationData
- project_dir
- measurement
responsible: !!python/tuple
- - SimulationData
- 2020_climate-model-predict
- '2020-02-01'
- README.md
- responsible
- - SimulationData
- project_dir
- measurement
- README
- responsible_single
Person:
first_name: !!python/tuple
- - SimulationData
- 2020_climate-model-predict
- '2020-02-01'
- README.md
- responsible
- - SimulationData
- project_dir
- measurement
- README
- responsible_single
last_name: !!python/tuple
- - SimulationData
- 2020_climate-model-predict
- '2020-02-01'
- README.md
- responsible
- - SimulationData
- project_dir
- measurement
- README
- responsible_single
Project:
date: !!python/tuple
- - SimulationData
- 2020_climate-model-predict
- - SimulationData
- project_dir
identifier: !!python/tuple
- - SimulationData
- 2020_climate-model-predict
- - SimulationData
- project_dir
...@@ -27,6 +27,7 @@ import caosdb as db ...@@ -27,6 +27,7 @@ import caosdb as db
from abc import abstractmethod from abc import abstractmethod
from .utils import get_value, has_parent from .utils import get_value, has_parent
class IdentifiableAdapter(object): class IdentifiableAdapter(object):
""" """
Base class for identifiable adapters. Base class for identifiable adapters.
...@@ -40,8 +41,8 @@ class IdentifiableAdapter(object): ...@@ -40,8 +41,8 @@ class IdentifiableAdapter(object):
- Identifiable is the concrete identifiable, e.g. the Record based on - Identifiable is the concrete identifiable, e.g. the Record based on
the registered identifiable with all the values filled in. the registered identifiable with all the values filled in.
- Identified record is the result of retrieving a record based on the identifiable - Identified record is the result of retrieving a record based on the
from the database. identifiable from the database.
General question to clarify: General question to clarify:
Do we want to support multiple identifiables per RecordType? Do we want to support multiple identifiables per RecordType?
...@@ -212,6 +213,10 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter): ...@@ -212,6 +213,10 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
def check_record(self, record: db.Record, identifiable: db.Record): def check_record(self, record: db.Record, identifiable: db.Record):
""" """
Check for a record from the local storage (named "record") if it is
the identified record for an identifiable which was created by
a run of the crawler.
Naming of the parameters could be confusing: Naming of the parameters could be confusing:
record is the record from the local database to check against. record is the record from the local database to check against.
identifiable is the record that was created during the crawler run. identifiable is the record that was created during the crawler run.
...@@ -222,13 +227,31 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter): ...@@ -222,13 +227,31 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
return False return False
for prop in identifiable.properties: for prop in identifiable.properties:
prop_record = record.get_property(prop.name) prop_record = record.get_property(prop.name)
if prop_record is None:
return False
# if prop is an entity, it needs to be resolved first. # if prop is an entity, it needs to be resolved first.
# there are two different cases: # there are two different cases:
# a) prop_record.value has a registered identifiable: # a) prop_record.value has a registered identifiable:
# in this case, fetch the identifiable and set the value accordingly # in this case, fetch the identifiable and set the value accordingly
if isinstance(prop.value, db.Entity):
registered = self.get_registered_identifiable(prop.value)
if registered is None:
raise NotImplementedError("Non-identifiable references cannot"
" be used as properties in identifiables.")
value_identifiable = self.retrieve_identified_record(prop.value)
if value_identifiable is None:
raise RuntimeError("The identifiable which is used as property"
" here has to be inserted first.")
if value_identifiable.id is None:
raise RuntimeError("The entity has not been assigned an ID.")
prop.value = value_identifiable.id
if prop_record is None:
return False
if prop.value != prop_record.value: if prop.value != prop_record.value:
if prop.name == "project": if prop.name == "project":
breakpoint() breakpoint()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment