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

Merge branch 'f-fix-ident-query' into 'dev'

F fix ident query

See merge request !48
parents 55a54e56 00e6cf94
Branches
Tags
2 merge requests!53Release 0.1,!48F fix ident query
Pipeline #29077 passed
{ {
"title": "Random numbers created on a random autumn day in a random office", "title": "Random numbers created on a random autumn day in a random person's office",
"abstract": "For demonstration purposes we created random numbers on a computer in an office of the CLOUD. This demonstration dataset is used in the DataCloud, a curated cloud storage for scientific data.", "abstract": "For demonstration purposes we created random numbers on a computer in an office of the CLOUD. This demonstration dataset is used in the DataCloud, a curated cloud storage for scientific data.",
"Event": [ "Event": [
{ {
......
...@@ -124,7 +124,7 @@ def test_dataset(clear_database, usemodel): ...@@ -124,7 +124,7 @@ def test_dataset(clear_database, usemodel):
" given_name='Max'", unique=True) " given_name='Max'", unique=True)
dataset = db.execute_query(f"FIND RECORD Dataset with Dataspace={dataspace.id} AND title=" dataset = db.execute_query(f"FIND RECORD Dataset with Dataspace={dataspace.id} AND title="
"'Random numbers created on a random autumn day in a random office'" "'Random numbers created on a random autumn day in a random person\\'s office'"
"", unique=True) "", unique=True)
assert db.execute_query(f"COUNT RECORD with id={dataset.id} AND WHICH REFERENCES Person WITH full_name=" assert db.execute_query(f"COUNT RECORD with id={dataset.id} AND WHICH REFERENCES Person WITH full_name="
"'Alexa Nozone' AND WHICH REFERENCES Person WITH full_name='Max Schmitt'" "'Alexa Nozone' AND WHICH REFERENCES Person WITH full_name='Max Schmitt'"
......
...@@ -52,8 +52,11 @@ def convert_value(value): ...@@ -52,8 +52,11 @@ def convert_value(value):
return str(value.id) return str(value.id)
elif isinstance(value, datetime): elif isinstance(value, datetime):
return value.isoformat() return value.isoformat()
elif type(value) == str:
# replace single quotes, otherwise they may break the queries
return value.replace("\'", "\\'")
else: else:
return str(value) return f"{value}"
class IdentifiableAdapter(metaclass=ABCMeta): class IdentifiableAdapter(metaclass=ABCMeta):
...@@ -387,7 +390,8 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter): ...@@ -387,7 +390,8 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
if self.check_record(record, identifiable): if self.check_record(record, identifiable):
candidates.append(record) candidates.append(record)
if len(candidates) > 1: if len(candidates) > 1:
raise RuntimeError("Identifiable was not defined unambigiously.") raise RuntimeError(
f"Identifiable was not defined unambigiously. Possible candidates are {candidates}")
if len(candidates) == 0: if len(candidates) == 0:
return None return None
return candidates[0] return candidates[0]
...@@ -469,7 +473,8 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter): ...@@ -469,7 +473,8 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter):
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:
raise RuntimeError("Identifiable was not defined unambigiously.") raise RuntimeError(
f"Identifiable was not defined unambigiously.\n{query_string}\nReturned the following {candidates}.")
if len(candidates) == 0: if len(candidates) == 0:
return None return None
return candidates[0] return candidates[0]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment