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
No related branches found
No related tags found
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.",
"Event": [
{
......
......@@ -124,7 +124,7 @@ def test_dataset(clear_database, usemodel):
" given_name='Max'", unique=True)
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)
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'"
......
......@@ -52,8 +52,11 @@ def convert_value(value):
return str(value.id)
elif isinstance(value, datetime):
return value.isoformat()
elif type(value) == str:
# replace single quotes, otherwise they may break the queries
return value.replace("\'", "\\'")
else:
return str(value)
return f"{value}"
class IdentifiableAdapter(metaclass=ABCMeta):
......@@ -387,7 +390,8 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
if self.check_record(record, identifiable):
candidates.append(record)
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:
return None
return candidates[0]
......@@ -469,7 +473,8 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter):
query_string = self.create_query_for_identifiable(identifiable)
candidates = db.execute_query(query_string)
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:
return None
return candidates[0]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment