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

FIX: added hash generator for file identifiables and tests for the identifiables cache

parent 88c72db6
No related branches found
No related tags found
1 merge request!53Release 0.1
...@@ -420,7 +420,7 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter): ...@@ -420,7 +420,7 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter):
return record return record
return record.id return record.id
def retrieve_identified_record(self, identifiable: db.Record): def retrieve_identified_record_for_identifiable(self, identifiable: db.Record):
query_string = self.create_query_for_identifiable(identifiable) query_string = self.create_query_for_identifiable(identifiable)
candidates = db.execute_query(query_string) candidates = db.execute_query(query_string)
if len(candidates) > 1: if len(candidates) > 1:
......
...@@ -36,6 +36,15 @@ def _create_hashable_string(identifiable: db.Record): ...@@ -36,6 +36,15 @@ def _create_hashable_string(identifiable: db.Record):
""" """
creates a string from the attributes of an identifiable that can be hashed creates a string from the attributes of an identifiable that can be hashed
""" """
if identifiable.role == "File":
# Special treatment for files:
return "P<>N<>{}:{}".format("path", identifiable.path)
if len(identifiable.parents) != 1:
# TODO: extend this
# maybe something like this:
# parent_names = ",".join(
# sorted([p.name for p in identifiable.parents])
raise RuntimeError("Cache entry can only be generated for entities with 1 parent.")
rec_string = "P<{}>N<{}>".format(identifiable.parents[0].name, identifiable.name) rec_string = "P<{}>N<{}>".format(identifiable.parents[0].name, identifiable.name)
for pname in sorted([p.name for p in identifiable.properties]): for pname in sorted([p.name for p in identifiable.properties]):
value = str(identifiable.get_property(pname).value) value = str(identifiable.get_property(pname).value)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment