Skip to content
Snippets Groups Projects

MAINT: remove `retrieve_identified_record_for_record` and `resolve_reference`

Merged Henrik tom Wörden requested to merge f-remove-foo into dev
2 files
+ 0
68
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -264,10 +264,6 @@ class IdentifiableAdapter(metaclass=ABCMeta):
"""
pass
@abstractmethod
def resolve_reference(self, record: db.Record):
pass
@abstractmethod
def get_file(self, identifiable: db.File):
warnings.warn(
@@ -409,28 +405,6 @@ class IdentifiableAdapter(metaclass=ABCMeta):
"""
pass
def retrieve_identified_record_for_record(
self, record: db.Record, referencing_entities=None
):
"""
This function combines all functionality of the IdentifierAdapter by
returning the identifiable after having checked for an appropriate
registered identifiable.
In case there was no appropriate registered identifiable or no identifiable could
be found return value is None.
"""
if record.path is not None:
return cached_get_entity_by(path=record.path)
if record.id is not None:
return cached_get_entity_by(eid=record.id)
identifiable = self.get_identifiable(
record, referencing_entities=referencing_entities
)
return self.retrieve_identified_record_for_identifiable(identifiable)
@staticmethod
def referencing_entity_has_appropriate_type(parents, register_identifiable):
"""returns true if one of the parents is listed by the 'is_referenced_by' property
@@ -585,26 +559,6 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
return None
return candidates[0]
def resolve_reference(self, value: db.Record):
if self.get_registered_identifiable(value) is None:
raise NotImplementedError(
"Non-identifiable references cannot"
" be used as properties in identifiables."
)
# TODO: just resolve the entity
value_identifiable = self.retrieve_identified_record_for_record(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.")
return value_identifiable.id
class CaosDBIdentifiableAdapter(IdentifiableAdapter):
"""
@@ -669,15 +623,6 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter):
if definition.parents[0].name.lower() == rt_name.lower():
return definition
def resolve_reference(self, record: db.Record):
"""
Current implementation just sets the id for this record
as a value. It needs to be verified that references all contain an ID.
"""
if record.id is None:
return record
return record.id
def retrieve_identified_record_for_identifiable(self, identifiable: Identifiable):
query_string = self.create_query_for_identifiable(identifiable)
try:
Loading